• Educational Codeforces Round 119 (Rated for Div. 2)


    Dashboard - Educational Codeforces Round 119 (Rated for Div. 2) - Codeforceshttps://codeforces.com/contest/1620

    A. Equal or Not Equal

    Problem - A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1620/problem/A

    统计E的数量,为1即输出"NO".

    1. #include<map>
    2. #include<cmath>
    3. #include<set>
    4. #include<queue>
    5. #include<string>
    6. #include<vector>
    7. #include<cstring>
    8. #include<iostream>
    9. #include<algorithm>
    10. #include<unordered_set>
    11. #include<unordered_map>
    12. #define int long long
    13. using namespace std;
    14. const int N =5e5+10,mod=998244353;
    15. void solve()
    16. {
    17. string s;
    18. cin>>s;
    19. int cnt=0;
    20. for(int i=0;i<s.size();i++)
    21. {
    22. if(s[i]=='N')
    23. cnt++;
    24. }
    25. if(cnt==1)
    26. cout<<"NO\n";
    27. else
    28. cout<<"YES\n";
    29. return ;
    30. }
    31. signed main()
    32. {
    33. int t;
    34. cin>>t;
    35. while( t--)
    36. solve();
    37. return 0;
    38. }

    B. Triangles on a Rectangle

    Problem - B - Codeforceshttps://codeforces.com/contest/1620/problem/B直接枚举,取最大值即可:

    1. #include<map>
    2. #include<cmath>
    3. #include<set>
    4. #include<queue>
    5. #include<string>
    6. #include<vector>
    7. #include<cstring>
    8. #include<iostream>
    9. #include<algorithm>
    10. #include<unordered_set>
    11. #include<unordered_map>
    12. #define int long long
    13. using namespace std;
    14. const int N =5e5+10,mod=998244353;
    15. int arr[200005];
    16. void solve()
    17. {
    18. int ans=0;
    19. int w,h,k,cheng;
    20. cin>>w>>h;
    21. for(int i=0;i<4;i++)
    22. {
    23. if(i<2)
    24. cheng=h;
    25. else
    26. cheng=w;
    27. cin>>k;
    28. for(int j=1;j<=k;j++)
    29. cin>>arr[j];
    30. sort(arr+1,arr+1+k);
    31. ans=max(ans,abs(arr[1]-arr[k])*cheng);
    32. }
    33. cout<<ans<<"\n";
    34. return ;
    35. }
    36. signed main()
    37. {
    38. int t;
    39. cin>>t;
    40. while(t--)
    41. solve();
    42. return 0;
    43. }

    C. BA-String

    Problem - C - Codeforcesicon-default.png?t=M5H6https://codeforces.com/contest/1620/problem/C题意:给你三个数字n,k,x,给你一个只含a,*的字符串 将其中的*替换成[ 0 , k ] 个b,问你所有情况中字典序第x 小的是什么。

    思路,我们可以把a当做一个分割符号,因为无论怎么变,a始终存在.这个字符串就可以看成很多个可以确定上限个数的只含字符b的子串和分割他们的只含a的子串.通过枚举,会发现,当分割的a子串(下面叫他分割串)右边的可变换长度的只含有b的子串(下面叫他变换串)子串中b的个数填满了,还要按照字典序向下遍历的时候,就需要在这个分割串的前一位加上一个b,才可以在后面的分割串继续从一个b开始增加.这就很类似于我们的进制,只不过这个题每一位的进制不一定是一样长.那么我们就可以计算好每个变换串的可变换长度,当做此位进制转换的个数,直接将字典序从0开始进行进制转换即可,在输出相应字符串.

    1. #include<map>
    2. #include<cmath>
    3. #include<set>
    4. #include<queue>
    5. #include<string>
    6. #include<vector>
    7. #include<cstring>
    8. #include<iostream>
    9. #include<algorithm>
    10. #include<unordered_set>
    11. #include<unordered_map>
    12. #define int long long
    13. using namespace std;
    14. void solve()
    15. {
    16. string s;
    17. int n,k,x;
    18. cin>>n>>k>>x;
    19. cin>>s;
    20. reverse(s.begin(),s.end());
    21. int cnt=0;
    22. string res="";
    23. x--;
    24. for(int i=0;i<s.size();i++)
    25. {
    26. if(s[i]=='a')
    27. {
    28. int num=x%(cnt*k+1);
    29. x/=(cnt*k+1);
    30. for(int i=0;i<num;i++)
    31. res+='b';
    32. res+='a';
    33. cnt=0;
    34. }
    35. else
    36. cnt++;
    37. }
    38. int num=x%(cnt*k+1);
    39. for(int i=0;i<num;i++)
    40. res+='b';
    41. reverse(res.begin(),res.end());
    42. cout<<res<<"\n";
    43. return ;
    44. }
    45. signed main()
    46. {
    47. int t;
    48. cin>>t;
    49. while(t--)
    50. solve();
    51. return 0;
    52. }

    E. Replace the Numbers

    Problem - E - Codeforcesicon-default.png?t=M5H6https://codeforces.com/contest/1620/problem/E题意:给你n次操作,每次输入一个数字,当这个数字是1时,在一个原本是空数组的末尾插入一个输入的数字x,当这个数字是2的时候,输入x和y,把所有现在在数组里面的x都变成y.

    这个题一开始模拟,很自然而然的t在23个样例.然后看题解,学到了一个并查集做法.

    我们直接把存放这相同数字的值的数组的位置(用位置记录),放在一个集合里面,如果要修改就只需要进行并查集的合并的操作了,吧两个并查集合并,然后由根节点指向一个值,这个值就是目前的这个位置放得数的值.详细注释在下面代码里.

    1. #include<map>
    2. #include<cmath>
    3. #include<set>
    4. #include<queue>
    5. #include<string>
    6. #include<vector>
    7. #include<cstring>
    8. #include<iostream>
    9. #include<algorithm>
    10. #include<unordered_set>
    11. #include<unordered_map>
    12. using namespace std;
    13. int fa[500005],num[500005],vis[500005];
    14. //fa记录的是父亲节点,好让很多个节点组成一个集合(当然这里面存的都是他们的序号)
    15. //vis记录的是某个序号的值,也就是对应序号应该存在数组里面的值
    16. //num记录的是某个存在数组里面的值的序号(这个存进去的序号时不一定的,只要是在一个集合里面的数都可以)
    17. int find(int x)
    18. {
    19. if(x!=fa[x])
    20. fa[x]=find(fa[x]);
    21. return fa[x];
    22. }
    23. //路径压缩并查集
    24. void solve()
    25. {
    26. int q,op,x,y,tot=0;
    27. scanf("%d",&q);
    28. for(int i=1;i<=500000;i++)
    29. fa[i]=i;
    30. while(q--)
    31. {
    32. scanf("%d",&op);
    33. if(op==1)
    34. {
    35. tot++;
    36. scanf("%d",&x);
    37. fa[tot]=tot;//记录父亲节点为自己
    38. vis[tot]=x;//给父亲节点赋值
    39. if(num[x])
    40. fa[tot]=num[x];
    41. //如果储存在数组中的值x已经包含有节点(初始化都是0,如果是0就说明数组里面没有这个数x)
    42. else
    43. num[x]=tot;
    44. //确定该数字在数组里存在,并且取集合里面一个数字来存储,由这个数我们可以直接find到它的父节点,也就可以直接确定vis里面的值
    45. }
    46. else
    47. {
    48. scanf("%d%d",&x,&y);
    49. if(num[x]&&x!=y)
    50. {
    51. //如果存在值为x的数字在数组中,并且x,y需要变化
    52. if(num[y])
    53. {
    54. fa[num[x]]=num[y];
    55. num[x]=0;
    56. }
    57. //如果存在有y的值在数组中,直接进行集合合并,当然,合并之后,值为x的集合就消失了,置为0
    58. else
    59. {
    60. num[y]=num[x];
    61. vis[num[x]]=y;
    62. num[x]=0;
    63. }
    64. //如果不存在y的值在数组中,直接把整个x的集合变换为y的结合,在把x集合消除
    65. }
    66. }
    67. }
    68. for(int i=1;i<=tot;i++)
    69. printf("%d ",vis[find(i)]);
    70. //输出父节点对应的vis值即可
    71. return ;
    72. }
    73. signed main()
    74. {
    75. solve();
    76. return 0;
    77. }

    斗奋力努

  • 相关阅读:
    win7上安装microsoft edge浏览器, 模拟ie11模式
    git简介和指令
    【极简python】第六章 for循环与while循环
    第一章 教育基础(04 教师专业发展)
    IP报文发送过程和原理
    【Python&语义分割】Segment Anything(SAM)模型交互式分割+掩膜保存(三)
    43、优惠券秒杀(超卖问题分析(乐观锁解决思路))
    给rust的cargo环境或gnome构建器安装rust-analyzer
    springcloud商城源码
    JAVA中的“抽象接口”
  • 原文地址:https://blog.csdn.net/qq_49593247/article/details/125541496