• Codeforces Round #293 (Div. 2)


    A

    题意:给出长度相等的两个字符串,s,t,问能否找到字典序比字符串s大同时比字符串t小的字符串。

    因为要找到符合题意的字符串,则应该让这个字符串尽可能和s相似,即为比s的字典序多1.

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring>  
     4 #include<algorithm>  
     5 using namespace std;
     6 
     7 char s[105],t[105];
     8 
     9 int main()
    10 {
    11     int i;
    12     cin>>s>>t;
    13     int len=strlen(s);
    14     for(i=len-1;i>=0;i--)
    15     {
    16         if(s[i]=='z') s[i]='a';
    17         else
    18         {
    19             s[i]++;
    20             break;
    21         }
    22     }
    23     if(strcmp(s,t)>=0) printf("No such string
    ");
    24     else printf("%s
    ",s);
    25 }
    View Code


    B

    题意:给出两个字符串,如果两个字母相同,且大小写相同,称为"YAY" 两个字母相同,但是大小写不同,称为"WHOOP",在保证得到的YAY最大的情况下,求YAY,WHOOP的个数。

    分别统计每个串中出现的字母的个数

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring>  
     4 #include<algorithm>  
     5 using namespace std;
     6 
     7 char a[200005],b[200005];
     8 int s[100],w[100];
     9 
    10 int main()
    11 {
    12     int len1,len2,i,j,ans=0,tmp=0,cnt=0;
    13     cin>>a;
    14     cin>>b;
    15     memset(s,0,sizeof(s));
    16     memset(w,0,sizeof(w));
    17     len1=strlen(a);
    18     len2=strlen(b);
    19     for( i=0;i<len1;i++) s[a[i]-64]++;
    20     for(j=0;j<len2;j++)  w[b[j]-64]++;
    21 //    printf("s[58]=%d
    ",s[58]);
    22 //    printf("w[26]=%d
    ",w[26]);
    23     
    24     for(i=1;i<=100;i++)
    25     {
    26         
    27         tmp=min(s[i],w[i]);
    28         ans+=tmp;
    29         s[i]=s[i]-tmp;
    30         w[i]=w[i]-tmp;
    31         
    32     }
    33     //    printf("s[58]=%d
    ",s[58]);
    34 //    printf("w[26]=%d
    ",w[26]);
    35     
    36     for(i=1;i<=100;i++)
    37     {
    38         if(i>26)
    39         cnt+=min(s[i],w[i-32]);
    40         else
    41         cnt+=min(s[i],w[i+32]);        
    42     }
    43     printf("%d %d
    ",ans,cnt);        
    44 }
    View Code

    C

    题意:给出n个app,给出要启动的软件m,给出每一页放置app的个数,每启动一个软件之后,将它与前面的软件换位置,(位置已经是1的时候不用换)问按键的总数。

    用一个数组将app的位置存下来,再模拟--

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring>  
     4 #include<algorithm>  
     5 using namespace std;
     6 
     7 int a[100005],pos[100005];
     8 
     9 int main()
    10 {
    11     int n,m,k,i,j,t,u;
    12     long long ans=0;
    13     scanf("%d %d %d",&n,&m,&k);
    14     for(i=0;i<n;i++)
    15     {
    16         scanf("%d",&a[i]);
    17         pos[a[i]]=i;
    18     }
    19     
    20     for(i=0;i<m;i++)
    21     {
    22         scanf("%d",&u);
    23         ans+=pos[u]/k+1;
    24         if(pos[u]!=0)
    25         {
    26             swap(a[pos[u]],a[pos[u]-1]);
    27             int tmp=pos[u];
    28             pos[a[tmp]]=tmp;
    29             pos[a[tmp-1]]=tmp-1;
    30         }        
    31     }
    32     printf("%I64d
    ",ans);
    33 }
    View Code

    D是概率dp==先占坑= =

    哎= =默默地0题滚粗--A题不知道写到哪儿去了(还是-做得不够啊--)

    B题在已经问到思路的情况下还是木有写出来--因为用的是s[a[i]-64]来统计个数,然后是52个字母,i<52= =(后来才查表在大写的Z和小写的a之间的ASCII码不是连续的) 把i改成<100就过了

    c题都木有看题,后来自己写的时候,被换位置搞晕了= =

    加油加油---go--go--

  • 相关阅读:
    每日英语:Here's Why You Won't Finish This Article
    每日英语:'Still Out Of Work?' How To Handle Holiday Small Talk
    每日英语:How to Spend Christmas in Asia
    每日英语:Losing It at the Movies: Silly Beats Sober in China's Box Office
    每日英语:How Do iPhone Photos Impact Our Experience?
    一种使用CSS固定表头和列的方法
    一个asp.net中使用的flash展示控件
    gridview中cell的选择和编辑
    asp.net 2.0中的profile对象简介
    gridview中使用方向键标记选中行
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4300773.html
Copyright © 2020-2023  润新知