• C. Complementary XOR CodeTON Round 3 (Div. 1 + Div. 2, Rated, Prizes)


    传送门

     

     题目意思:给你两个01字符串ab,你可以选择一个范围l,r,使 a字符串的l<=i<=r" role="presentation">l<=i<=r 都变成1-a[i](0变1,1变0),而b使除了l,r(包含)的范围外,都变成1-b[i].问你能不能通过最多n+5次操作,使a和b都全为0?

    思路:从全部都是0开始模拟,我们发现, 只要进行奇数次操作,ab的每一位一定不一样;如果进行偶数次操作,那么ab每一位一定一样。那么对于ab,只有全是相反的或者全部相同才可以使ab全部为0,否则就不可以

    那么从a看,我使a全部变成0,那么b要么是0,要么是1。如果是0的话,直接输出对应的操作就好了。如果都是1,可以再多三次操作。

    [1n112n]" role="presentation">[1n112n]使b全部为0,那么最多的次数也不会超过n+3。

    然后怎么看是否全为1,就可以在每次操作后用差分保存第一位的状态(b在操作后要么全为1,要么全为0)

          c[1]+=1,c[i]-=1,c[i+1]+=1;

    如果c[1]是奇数的话就换符号 ,最后看b[1]的结果就好了。

    代码:

    1. /**
    2. *  ┏┓   ┏┓+ +
    3. * ┏┛┻━━━┛┻┓ + +
    4. * ┃       ┃
    5. * ┃   ━   ┃ ++ + + +
    6. * ████━████+
    7. * ◥██◤ ◥██◤ +
    8. * ┃   ┻   ┃
    9. * ┃       ┃ + +
    10. * ┗━┓   ┏━┛
    11. *   ┃   ┃ + + + +Code is far away from  
    12. *   ┃   ┃ + bug with the animal protecting
    13. *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
    14. *   ┃       ┣┓
    15. *   ┃        ┏┛
    16. *  ┗┓┓┏━┳┓┏┛ + + + +
    17. *    ┃┫┫ ┃┫┫
    18. *    ┗┻┛ ┗┻┛+ + + +
    19. */
    20. #include
    21. #include
    22. #include
    23. #include
    24. #include
    25. #include
    26. #include
    27. #include
    28. #include
    29. #define sc_int(x) scanf("%d", &x)
    30. #define sc_ll(x) scanf("%lld", &x)
    31. #define pr_ll(x) printf("%lld", x)
    32. #define pr_ll_n(x) printf("%lld\n", x)
    33. #define pr_int_n(x) printf("%d\n", x)
    34. #define ll long long
    35. using namespace std;
    36. const int N=1000000+100;
    37. int n ,m,h;
    38. ll s[N];
    39. int a[N],b[N];
    40. int c[N];
    41. vectorint,int>>q;
    42. void init()
    43. {
    44. char x;
    45. for(int i =1;i<=n;i++)
    46. {
    47. cin>>x;
    48. a[i]=x-'0';
    49. }
    50. for(int i =1;i<=n;i++)
    51. {
    52. cin>>x;
    53. b[i]=x-'0';
    54. }
    55. }
    56. int main()
    57. {
    58. int t;
    59. sc_int(t);
    60. while(t--)
    61. {
    62. for(int i =1;i<=n;i++)c[i]=0;
    63. sc_int(n);
    64. init();
    65. int flag=0;
    66. for(int i =1;i<=n;i++)
    67. if(a[i]!=b[i])flag++;
    68. if(flag>0&&flag!=n){
    69. cout<<"NO\n";
    70. }
    71. else
    72. {
    73. cout<<"YES\n";
    74. for(int i =1;i<=n;i++)
    75. {
    76. if(a[i]==1){
    77. q.push_back({i,i});
    78. c[1]+=1,c[i]-=1,c[i+1]+=1;
    79. }
    80. }
    81. if(c[1]%2!=0) b[1]=1-b[1];
    82. if(b[1]!=0)
    83. {
    84. q.push_back({1,n});
    85. q.push_back({1,1});
    86. q.push_back({2,n});
    87. }
    88. cout<size()<
    89. for(int i =0;isize();i++){
    90. cout<" "<
    91. }
    92. q.erase(q.begin(),q.end());
    93. }
    94. }
    95. return 0;
    96. }

    :感觉时间卡的有点紧

    如果有可以优化的地方那就可以自行优化~。 

  • 相关阅读:
    maven
    C++二分算法的应用:寻找峰值原理、源码及测试用例
    VR直播系统设置大揭秘,带你穿越时空亲临现场
    第七章 数学 AcWing 1533. 1 的个数
    xss标签和属性爆破
    串的基本操作(数据结构)
    【Rust】002-基础语法:函数
    Dockerfile 命令详解及最佳实践
    【电巢】新能源产业景气度加速向上,功率器件3000亿赛道国产替代已在路上!(附70+厂家名单&部分厂家替代型号)
    基于 PowerMax 架构的银行双活数据中心实践分享
  • 原文地址:https://blog.csdn.net/jikelk/article/details/127844202