【CF闯关练习】—— 1200分

🌏博客主页:PH_modest的博客主页
🚩当前专栏:cf闯关练习
💌其他专栏:
🔴每日一题
🟡 C++跬步积累
🟢 C语言跬步积累
🌈座右铭:广积粮,缓称王!

一.关卡1

👉传送门:1914D - Three Activities👈
在这里插入图片描述

1.Tutorial

直接找每个项目中最大的三个数,然后暴力枚举这三个数找最优解

2.Solution

//https://codeforces.com/problemset/problem/1914/D
//直接找每个项目中最大的三个数,然后暴力枚举这三个数找最优解
//
#include<iostream>
#include<algorithm>
#include<string>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<cstring>
#define int long long
using namespace std;

struct node
{
	int x;
	int p;
};
node a[200020];
node b[200020];
node c[200020];
bool cmp(node& a,node& b)
{
	return a.x>b.x;
}

void solve()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].x;
		a[i].p=i;
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i].x;
		b[i].p=i;
	}
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x;
		c[i].p=i;
	}
	sort(a,a+n,cmp);
	sort(b,b+n,cmp);
	sort(c,c+n,cmp);
	int ans=0;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int r=0;r<3;r++)
			{
				if(a[i].p!=b[j].p&&b[j].p!=c[r].p&&a[i].p!=c[r].p)
				{
					int tmp=a[i].x+b[j].x+c[r].x;
					ans=max(ans,tmp);
				}
			}
		}
	}
	cout<<ans<<"\n";
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}



3.Conclusion

结构体有时候真的很好用,特别是这种下标和值都有意义的时候


二.关卡2

👉传送门:1886B - Fear of the Dark👈
在这里插入图片描述

1.Tutorial

分情况讨论,求每种情况下点之间距离的最大值,再求这几种情况下最大值中的最小值

  1. 第一种情况:原点和p点都在一个圆内,这种情况下只需要求圆心到这两点之间的距离,求个最大值即可;
  2. 第二种情况:需要两个圆相切,即原点和p点分别在一个圆内,此时需要求max(原点到所在圆的圆心的距离,p点到所在圆的圆心的距离,两个圆心之间距离的一半);
  3. 最后将这两个情况取个最小值即可

2.Solution

//https://codeforces.com/problemset/problem/1886/B
//分情况讨论,求每种情况下点之间距离的最大值,再求这几种情况下最大值中的最小值
//
#include<bits/stdc++.h>
#define int long long

using namespace std;

struct Point
{
	double x;
	double y;
};
Point o,p,a,b;

double dist(Point& a,Point& b)
{
	return hypot(a.x-b.x,a.y-b.y);
}

void solve()
{
	cin>>p.x>>p.y;
	cin>>a.x>>a.y;
	cin>>b.x>>b.y;
	o.x=0,o.y=0;
	double ans=min({
	max(dist(o,a),dist(a,p)),
	max(dist(o,b),dist(b,p)),
	max({dist(a,o),dist(a,b)/2,dist(b,p)}),
	max({dist(b,o),dist(a,b)/2,dist(a,p)})
	});
	cout<<ans<<"\n";
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(10);//fixed()函数只需要出现一次,之后输出格式都会和这次一样
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}



3.Conclusion

  • 求给定数字的斜边可以用hypot()函数,hypot(x,y)等价于sqrt(x * x + y * y)
  • 浮点数控制输出精度可以用fixed()+setprecision()

三.关卡3

👉传送门: D - Super-Permutation👈
在这里插入图片描述

1.Tutorial

首先第一个数肯定是输出n,然后当n为奇数时不行,偶数的时候从1~n-1开始遍历,遇到奇数输出n-i,否则输出i

2.Solution

//https://codeforces.com/problemset/problem/1822/D
//首先第一个数肯定是输出n,然后奇数不行,偶数的时候从1~n-1,遇到奇数输出n-i,否则输出i
//
#include<bits/stdc++.h>
#define int long long
using namespace std;



void solve()
{
    int n;
    cin>>n;
    if(n==1) cout<<"1"<<"\n";
    else if(n%2==1) cout<<"-1"<<"\n";
    else
    {
    	cout<<n<<" ";
    	for(int i=1;i<(n-2);i+=2)
    	{
    		cout<<n-i<<" "<<i+1<<" ";
		}
		cout<<"1\n";
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}




最后:

闯关系列旨在养成刷题的习惯,所以对代码的解释并不会特别详细,但足够引导大家写出来,选的题目都不会特别难,但也不是特别简单,比较考验大家的基础和应用能力,我希望能够将这个系列一直写下去,也希望大家能够和我一起坚持每天写代码。

之后每个星期都会不定期更新codeforces和atcoder上的题目,想要学习算法的友友们千万别错过了,有什么疑问欢迎大家在评论区留言或者私信博主!

在这里送大家一句话:广积粮,缓称王!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PH_modest

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值