🌏博客主页: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
分情况讨论,求每种情况下点之间距离的最大值,再求这几种情况下最大值中的最小值
- 第一种情况:原点和p点都在一个圆内,这种情况下只需要求圆心到这两点之间的距离,求个最大值即可;
- 第二种情况:需要两个圆相切,即原点和p点分别在一个圆内,此时需要求max(原点到所在圆的圆心的距离,p点到所在圆的圆心的距离,两个圆心之间距离的一半);
- 最后将这两个情况取个最小值即可
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
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上的题目,想要学习算法的友友们千万别错过了,有什么疑问欢迎大家在评论区留言或者私信博主!
在这里送大家一句话:广积粮,缓称王!