A题:水题。。
#include<stdio.h>
#include<string.h>
const int maxn = ;
char s[ maxn ];
int main(){
//freopen("in.txt","r",stdin);
while( scanf("%s",s)!=EOF ){
int len = strlen(s);
int c1 = ,c2 = ,c3 = ;
for( int i=;i<len;i++ ){
if( s[i]=='' ) c1++;
if( s[i]=='' ) c2++;
if( s[i]=='' ) c3++;
}
int sum = c1+c2+c3;
if( sum== ){
printf("%s\n",s);
continue;
}
for( int i=;i<sum;i++ ){
if( i== ){
if( c1 ) printf(""),c1--;
else if( c2 ) printf(""),c2--;
else if( c3 ) printf(""),c3--;
}
else{
if( c1 ) printf("+1"),c1--;
else if( c2 ) printf("+2"),c2--;
else if( c3 ) printf("+3"),c3--;
}
}
printf("\n");
}
return ;
}
B题:还是水题。。模拟。。
#include<stdio.h>
const int maxn = ;
typedef long long LL;
LL a[ maxn ];
int main(){
int n,m;
//freopen("in.txt","r",stdin);
while( scanf("%d%d",&n,&m)== ){
for( int i=;i<=m;i++ ){
scanf("%I64d",&a[i]);
}
LL sum = ;
for( int i=;i<=m;i++ ){
if( i== ){
sum += a[i]-;
}
else {
if( a[i]>=a[i-] ) sum += (a[i]-a[i-]);
else sum += (n+a[i]-a[i-]);
}
}
printf("%I64d\n",sum);
}
return ;
}
C题:简单的DFS,满足两个条件即可。。。
题意别理解错!!!!!!!!!!!!!!!!!
#include<stdio.h>
#include<string.h>
const int maxn = ;
int ans[ maxn ];
//int cnt ;
char str[ maxn ];
int m;
bool ok; void dfs( int L,int R,int sL,int sR,int cnt ){
if( cnt==m&&ok==false ){
ok = true;
return ;
}
if( ok==true ) return ;
for( int i=;str[i]!='\0';i++ ){
if( str[i]=='' ){
if( cnt%==&&((i+)!=R)&&(sL+i+>sR) ){
ans[ cnt ] = i+;
dfs( i+,R,sL+i+,sR,cnt+ );
}
if( ok==true ) return ;
if( cnt%==&&((i+)!=L)&&(sR+i+>sL) ){
ans[ cnt ] = i+;
dfs( L,i+,sL,sR+i+,cnt+ );
}
if( ok==true ) return ;
}
}
return;
} int main(){
//freopen("in.txt","r",stdin);
scanf("%s%d",str,&m);
ok = false;
if( m== ){
for( int i=;str[i]!='\0';i++ ){
if( str[i]=='' ){
ok = true;
printf("YES\n%d\n",i+);
break;
}
}
if( ok==false ) printf("NO\n");
return ;
}
ok = false;
dfs( ,,,, );
if( ok==true ){
puts("YES");
for( int i=;i<m;i++ ){
if( i== ) printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
printf("\n");
}
else puts("NO"); return ;
}