Codeforces Round #541 (Div. 2)(ABCF)

水深无声 2023-06-03 13:52 40阅读 0赞

A. Sea Battle(水)

题意:两个长方形拼在一起,求出拼完后周围的面积;

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int a1,b1,a2,b2;
  5. cin>>a1>>b1>>a2>>b2;
  6. int ans=a1+2*b1+abs(a1-a2)+a2+2*b2;
  7. cout<<ans+4<<endl;
  8. return 0;
  9. }

B. Draw!

题意:从(0,0)开始,给出n个分数,问最大可能平局的次数;

转化成求两个区间相交的点有多少;模拟一遍就行了;

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int maxn=1e5+10;
  5. int main(){
  6. ll n,a,b,x;
  7. cin>>n;
  8. ll ans=1LL;
  9. ll lasta=0,lastb=0;
  10. for(int i=1;i<=n;i++){
  11. cin>>a>>b;
  12. if(a>=b){
  13. if(lasta>=lastb){
  14. x=b-lasta;
  15. }
  16. else{
  17. x=b-lastb;
  18. }
  19. if(lasta!=lastb)x++;
  20. if(x<0)x=0;
  21. ans+=x;
  22. }
  23. else{
  24. if(lastb>=lasta){
  25. x=a-lastb;
  26. }
  27. else {
  28. x=a-lasta;
  29. }
  30. if(lasta!=lastb)x++;
  31. if(x<0)x=0;
  32. ans+=x;
  33. }
  34. lasta=a;lastb=b;
  35. //cout<<ans<<endl;
  36. }
  37. cout<<ans<<endl;
  38. return 0;
  39. }
  40. /*
  41. 3
  42. 5 6 5 7 5 8
  43. */

C. Birthday

题意:n个人,围成一圈,重排序,让全部相邻的两个差值最小;

解:排序,然后跳着输出,1-3-5-7-9…… 然后从后面再往前面输出每输出过的值

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int maxn=1e3+10;
  5. ll a[maxn],b[maxn],c[maxn];
  6. bool vis[maxn];
  7. int main(){
  8. int n;
  9. cin>>n;
  10. ll maxx=0;
  11. for(int i=1;i<=n;i++){
  12. cin>>a[i];
  13. maxx=max(a[i],maxx);
  14. }
  15. sort(a+1,a+1+n);
  16. for(int i=1;i<=n;i+=2){
  17. cout<<a[i]<<' ';
  18. vis[i]=true;
  19. }
  20. if(n%2==0){
  21. cout<<a[n]<<' ';
  22. vis[n]=true;
  23. }
  24. for(int i=n;i>=1;i--){
  25. if(!vis[i])cout<<a[i]<<' ';
  26. }
  27. cout<<endl;
  28. return 0;
  29. }

F. Asya And Kittens

题意:n个格子,每次给出一对x,y,说明x,y相邻,然后输出最初始的样子;

解:并查集,然后输出路径;

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=3e5+10;
  4. vector<int>g[maxn];
  5. int f[maxn];
  6. int find(int x){
  7. return x==f[x]?x:f[x]=find(f[x]);
  8. }
  9. void gao(int x){
  10. cout<<x<<' ';
  11. for(int i=0;i<g[x].size();i++){
  12. gao(g[x][i]);
  13. }
  14. }
  15. int main(){
  16. int n;
  17. cin>>n;
  18. int rt;
  19. for(int i=1;i<=n;i++)f[i]=i;
  20. for(int i=1;i<=n-1;i++){
  21. int u,v;
  22. cin>>u>>v;
  23. int uu=find(u),vv=find(v);
  24. if(uu==vv)continue;
  25. rt=uu;
  26. g[rt].push_back(vv);
  27. f[vv]=uu;
  28. }
  29. gao(rt);
  30. cout<<endl;
  31. return 0;
  32. }

转载于:https://www.cnblogs.com/lin1874/p/11381631.html

发表评论

表情:
评论列表 (有 0 条评论,40人围观)

还没有评论,来说两句吧...

相关阅读

    相关 codeforces-round375-div2

    题目链接:[codeforces round 375 div2][] A题: 读一遍题目就知道是超级水的题目,,就是给你三个坐标,求三个坐标汇集到一个点所走的路程