zoukankan      html  css  js  c++  java
  • Codeforces Round #373 (Div. 2)

    题目链接:Codeforces Round #373 (Div. 2)

    分析:只补了B,C,其他题再看看,做出几道说几道,QAQ

            B题有两种操作,一种是交换两个字母的位置,另一种是改变字母,使得最后序列成为一个形如drdrd/rdrdr的序列。

    在两种情况中取较小值。

       我将奇数与偶数次位置分开处理,如果交换,则两个都加一;如果改变字母,则对应的奇/偶位置++,取两者较大者。

    详情见代码:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 char s[100100];
     7 int op1,op2,n;
     8 
     9 int check(char c)
    10 {
    11     int cou[2]={0,0};
    12     for(int i=1;i<=n;++i) if((s[i]==c) != (i&1)) cou[i&1]++;
    13     return max(cou[0],cou[1]);
    14 }
    15 int main()
    16 {
    17     scanf("%d",&n);
    18     scanf("%s",s+1);
    19     printf("%d
    ",min(check('b'),check('r')));
    20 }
    View Code

      C题题意是t秒后能得到的最大值,那么首先要找到小数点后的第一个不小于5的数,然后往回处理,详情见代码。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 char s[200200];
     7 int pos,n,t,loc;
     8 bool flag,vis;
     9 
    10 int main()
    11 {
    12     scanf("%d %d",&n,&t);
    13     scanf("%s",s);
    14     while(s[loc]!='.' && loc < n) loc++;
    15     pos=loc+1;
    16     while(pos < n && s[pos] < '5') pos++; 
    17     if(pos == n) {printf("%s
    ",s);return 0;}
    18     while(t > 0)
    19     {
    20         t--,pos--;
    21         while(s[pos] == '9') pos--;
    22         //printf("%s
    ",s);
    23         if(s[pos] == '.')
    24         {
    25             //printf("%s
    ",s);
    26             pos--;
    27             while(pos >= 0 && s[pos] == '9') {s[pos] = '0';pos--;}
    28             if(pos >= 0) 
    29             {
    30                 s[pos]++;
    31                 for(int i=0;i<loc;++i) printf("%c",s[i]);puts("");
    32                 return 0;
    33             }
    34             printf("1");
    35             for(int i=0;i<loc;++i) printf("%c",s[i]);puts("");
    36             return 0;
    37         }
    38         s[pos]++;
    39         if(s[pos] < '5') break; 
    40     }
    41     for(int i = 0;i <= pos;++i) printf("%c",s[i]);puts("");
    42 }
    View Code

       

  • 相关阅读:
    临时文件服务器,配置共享文件夹
    封装扩展方法
    List.Insert
    VS 生成事件中xcopy失败
    创建型设计模式总结
    js提交图片转换为base64
    C#建造者模式
    echarts 立体柱
    k8s生产环境启用防火墙,要开启的端口
    一篇文章为你图解Kubernetes网络通信原理
  • 原文地址:https://www.cnblogs.com/chendl111/p/5902879.html
Copyright © 2011-2022 走看看