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 }
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 }
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]!='