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


    A.

    最优直接用第一个人的力量值即可,比他小的数都不用思考,力量值比他大的如果耐力值也比他大于等于那就一定-1,否则输出第一个人的力量值即可

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. const int N = 2e5+10,mod=1e9+7;
    4. #define int long long
    5. typedef long long LL;
    6. typedef pair<int, int> PII;
    7. int n,m;
    8. PII a[N];
    9. void solve(){
    10. cin>>n;
    11. map<PII,int> mp;
    12. for(int i=1;i<=n;i++){
    13. cin>>a[i].first>>a[i].second;
    14. mp[{a[i].first,a[i].second}]++;
    15. }
    16. int c=a[1].first,d=a[1].second;
    17. if(mp[{a[1].first,a[1].second}]>1){
    18. cout<<"-1\n";
    19. return ;
    20. }
    21. sort(a+1,a+1+n,[&](const auto&p,const auto&q){
    22. return p.first<q.first;
    23. });
    24. int mx=0;
    25. int idx;
    26. for(int i=1;i<=n;i++){
    27. if(a[i].first==c&&a[i].second==d){
    28. idx=i;
    29. break;
    30. }
    31. }
    32. for(int i=1;i<=n;i++)
    33. {
    34. if(i==idx) continue;
    35. if(a[i].first>=c) mx=max(mx,a[i].second);
    36. }
    37. if(mx>=d){
    38. cout<<-1<<"\n";
    39. return ;
    40. }
    41. cout<<c<<"\n";
    42. }
    43. signed main(){
    44. cin.tie(0);ios::sync_with_stdio(0);
    45. int t=1;
    46. cin>>t;
    47. while(t--) solve();
    48. }

    B.

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. const int N = 3e5+10,mod=1e9+7;
    4. #define int long long
    5. typedef long long LL;
    6. typedef pair<int, int> PII;
    7. int n,m;
    8. int a[N],b[N];
    9. void solve(){
    10. cin>>n;
    11. //4 6 3
    12. //7 6 6
    13. //4 3 3
    14. for(int i=1;i<=n;i++) cin>>a[i];
    15. for(int i=1;i<=n;i++) cin>>b[i];
    16. int mn=*min_element(a+1,a+1+n);
    17. int mn1=*min_element(b+1,b+1+n);
    18. int res1=0,res2=0;
    19. for(int i=1;i<=n;i++) res1+=(mn+b[i]);
    20. for(int i=1;i<=n;i++)
    21. res2+=(mn1+a[i]);
    22. cout<<min(res1,res2)<<"\n";
    23. }
    24. signed main(){
    25. cin.tie(0);ios::sync_with_stdio(0);
    26. int t=1;
    27. cin>>t;
    28. while(t--) solve();
    29. }

    C.

    理性分析:要么开头是0,要么开头1开始,所以可以枚举是1开头还是0开头

    然后发现其实没必要,直接以字符串第一个字符开头就行,

    我们先把每段连续的缩点

    每个点里面只选一个数出来,其他点都要删

    所以最小次数就是每个点的总和-点的总数

    方案数就是要删除的个数的阶乘  * 每个点选择哪一个点出来当合法的0/1

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. const int N = 3e5+10,mod=998244353;
    4. #define int long long
    5. typedef long long LL;
    6. typedef pair<int, int> PII;
    7. int n,m;
    8. string s;
    9. int fact[N];
    10. void init(){
    11. fact[0]=1;
    12. for(int i=1;i<N;i++){
    13. fact[i]=(LL)fact[i-1]*i%mod;
    14. }
    15. }
    16. // PII get1()
    17. // {
    18. // int cnt=1,now=0;
    19. // int res=0;
    20. // vector<PII> a;
    21. // a.push_back({(s[1]-'0'),0});
    22. // for(int i=1;i<=n;i++)
    23. // {
    24. // int x=s[i]-'0';
    25. // if(a.back().first==x) a.back().second++;
    26. // else a.push_back({x,1});
    27. // }
    28. // PII get2(){
    29. // int cnt=0,now=1;
    30. // int res=0;
    31. // vector<PII> a;
    32. // a.push_back({(s[1]-'0'),0});
    33. // for(int i=1;i<=n;i++)
    34. // {
    35. // int x=s[i]-'0';
    36. // if(a.back().first==x) a.back().second++;
    37. // else a.push_back({x,1});
    38. // }
    39. // ///000000
    40. // for(auto [x,v]:a)
    41. // {
    42. // cnt+=v;
    43. // if(x==now)
    44. // {
    45. // now^=1;
    46. // res+=v-1;
    47. // }
    48. // else
    49. // {
    50. // res+=v;
    51. // }
    52. // }
    53. // return {res,fact[cnt]};
    54. // }
    55. void solve(){
    56. cin>>s;
    57. n=s.size();
    58. s="?"+s;
    59. vector<PII> a;
    60. a.push_back({(s[1]-'0'),0});
    61. for(int i=1;i<=n;i++)
    62. {
    63. int x=(s[i]-'0');
    64. if(a.back().first==x) a.back().second++;
    65. else a.push_back({x,1});
    66. }
    67. int cnt=1,res=0;
    68. for(auto [x,v]:a)
    69. {
    70. res+=v-1;
    71. cnt=cnt*v%mod;
    72. }
    73. cout<<res<<" "<<cnt*fact[res]%mod<<"\n";
    74. }
    75. signed main(){
    76. cin.tie(0);ios::sync_with_stdio(0);
    77. int t=1;
    78. init();
    79. cin>>t;
    80. while(t--) solve();
    81. }

    D:异或和考虑每个二进制进行思考

    先进行前缀异或和,变成选两个数(s【r】^s[l-1])*(r-l+1)

    如果第i下标的某个二进制当前位是1,那么我只要前面的数二进制当前位是0的数,否则答案是0不用考虑

    考虑r-l+1

    统计前面有多少个数异或和为0的个数,和异或和为0下标总和

    然后(r-l+1)=个数*r-下标总和即可,(因为是s[l-1],所以那个+1已经考虑进去了)

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. const int N =3e5+10,mod= 998244353;
    4. #define int long long
    5. typedef long long LL;
    6. typedef pair<int, int> PII;
    7. int n,m;
    8. int a[N];
    9. int s[N];
    10. int cnt[2][35];
    11. int d[2][35];
    12. void solve()
    13. {
    14. cin>>n;
    15. for(int i=1;i<=n;i++) cin>>a[i];
    16. int res=0;
    17. //1 2 3 3
    18. for(int i=1;i<=n;i++)
    19. s[i]=a[i]^s[i-1];
    20. for(int i=0;i<=n;i++)
    21. {
    22. for(int j=0;j<=30;j++)
    23. {
    24. int now=0;
    25. if(s[i]>>j&1) now=0,d[1][j]=(d[1][j]+i)%mod;
    26. else now=1,d[0][j]=(d[0][j]+i)%mod;
    27. res+=(1<<j)%mod*(cnt[now][j]*i%mod-d[now][j])%mod;
    28. res=(res%mod+mod)%mod;
    29. cnt[now^1][j]++;
    30. }
    31. }
    32. cout<<(res%mod+mod)%mod;
    33. }
    34. signed main(){
    35. cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    36. int t=1;
    37. // cin>>t;
    38. while(t--) solve();
    39. }

  • 相关阅读:
    socket学习一、socket、bind/connect、listen函数详解
    Flutter高仿微信-第22篇-支付-二维码收款(二维码)
    赶紧进来!!!带你认识C语言基本数据类型
    【Java 进阶篇】JQuery 遍历:发现元素的魔法之旅
    齐次坐标得到非齐次坐标
    55、MINE: Towards Continuous Depth MPI with NeRF for Novel View Synthesis
    使用@Constraint和自定义注解校验接口入参
    Python3虚拟环境之pipenv
    [数据分析与可视化] 基于matplotlib-scalebar库绘制比例尺
    Autosar MCAL-ADC详解(二)-基于Tc27x的cfg软件
  • 原文地址:https://blog.csdn.net/qq_61657632/article/details/133269950