zoukankan      html  css  js  c++  java
  • CodeForce 339:A+B+C

    A题:水题。。

     1 #include<stdio.h>
     2 #include<string.h>
     3 const int maxn = 1005;
     4 char s[ maxn ];
     5 int main(){
     6     //freopen("in.txt","r",stdin);
     7     while( scanf("%s",s)!=EOF ){
     8         int len = strlen(s);
     9         int c1 = 0,c2 = 0,c3 = 0;
    10         for( int i=0;i<len;i++ ){
    11             if( s[i]=='1' ) c1++;
    12             if( s[i]=='2' ) c2++;
    13             if( s[i]=='3' ) c3++;
    14         }
    15         int sum = c1+c2+c3;
    16         if( sum==1 ){
    17             printf("%s
    ",s);
    18             continue;
    19         }
    20         for( int i=0;i<sum;i++ ){
    21             if( i==0 ){
    22                 if( c1 ) printf("1"),c1--;
    23                 else if( c2 ) printf("2"),c2--;
    24                 else if( c3 ) printf("3"),c3--;
    25             }
    26             else{
    27                 if( c1 ) printf("+1"),c1--;
    28                 else if( c2 ) printf("+2"),c2--;
    29                 else if( c3 ) printf("+3"),c3--;
    30             }
    31         } 
    32         printf("
    ");
    33     }
    34     return 0;
    35 }
    View Code

    B题:还是水题。。模拟。。

     1 #include<stdio.h>
     2 const int maxn = 100005;
     3 typedef long long LL;
     4 LL a[ maxn ];
     5 int main(){
     6     int n,m;
     7     //freopen("in.txt","r",stdin);
     8     while( scanf("%d%d",&n,&m)==2 ){
     9         for( int i=1;i<=m;i++ ){
    10             scanf("%I64d",&a[i]);
    11         }
    12         LL sum = 0;
    13         for( int i=1;i<=m;i++ ){
    14             if( i==1 ){
    15                 sum += a[i]-1;
    16             }
    17             else {
    18                 if( a[i]>=a[i-1] ) sum += (a[i]-a[i-1]);
    19                 else sum += (n+a[i]-a[i-1]);
    20             }
    21         }
    22         printf("%I64d
    ",sum);
    23     }
    24     return 0;
    25 }
    View Code

    C题:简单的DFS,满足两个条件即可。。。

    题意别理解错!!!!!!!!!!!!!!!!!

     1 #include<stdio.h>
     2 #include<string.h>
     3 const int maxn = 1005;
     4 int ans[ maxn ];
     5 //int cnt ;
     6 char str[ maxn ];
     7 int m;
     8 bool ok;
     9 
    10 void dfs( int L,int R,int sL,int sR,int cnt ){
    11     if( cnt==m&&ok==false ){
    12         ok = true;
    13         return ;
    14     }
    15     if( ok==true ) return ;
    16     for( int i=0;str[i]!='';i++ ){
    17         if( str[i]=='1' ){
    18             if( cnt%2==0&&((i+1)!=R)&&(sL+i+1>sR) ){
    19                 ans[ cnt ] = i+1;
    20                 dfs( i+1,R,sL+i+1,sR,cnt+1 );
    21             }
    22             if( ok==true ) return ;
    23             if( cnt%2==1&&((i+1)!=L)&&(sR+i+1>sL) ){
    24                 ans[ cnt ] = i+1;
    25                 dfs( L,i+1,sL,sR+i+1,cnt+1 );
    26             }
    27             if( ok==true ) return ;
    28         }
    29     }
    30     return;
    31 }
    32 
    33 
    34 int main(){
    35     //freopen("in.txt","r",stdin);
    36         scanf("%s%d",str,&m);
    37         ok = false;
    38         if( m==1 ){
    39             for( int i=0;str[i]!='';i++ ){
    40                 if( str[i]=='1' ){
    41                     ok = true;
    42                     printf("YES
    %d
    ",i+1);
    43                     break;
    44                 }
    45             }
    46             if( ok==false ) printf("NO
    ");
    47             return 0;
    48         }
    49         ok = false;
    50         dfs( 0,0,0,0,0 );
    51         if( ok==true ){
    52             puts("YES");
    53             for( int i=0;i<m;i++ ){
    54                 if( i==0 ) printf("%d",ans[i]);
    55                 else printf(" %d",ans[i]);
    56             }
    57             printf("
    ");
    58         }
    59         else puts("NO");
    60     
    61     return 0;
    62 }
    View Code
    keep moving...
  • 相关阅读:
    使用nmon进行系统监控
    linux中内存使用原理
    测试网站访问速度的5个方法
    手机站点击商务通无轨迹解决方法
    PHP开启伪静态配置
    Phpcms V9当前栏目及所有二级栏目下内容调用标签
    手机访问网跳转到手机端
    移动端web开发技巧 -- 转载
    php错误:You don't have permission to access / on this server.
    Navicat for MySQL使用手记(上)--创建数据库和表
  • 原文地址:https://www.cnblogs.com/xxx0624/p/3288205.html
Copyright © 2011-2022 走看看