比赛的时候这题是zjy写的,1A了
下来重写,因为一直没考虑到6 2 2 221110 这种情况,wa了好几次。
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #define INF 1E9 using namespace std; int main() { int n,a,b,na,nb; string s; while(~scanf("%d%d%d",&n,&a,&b)) { cin>>s; if(a+b>n){cout<<-1<<endl;continue;} int i; na=nb=0; int ans=0; bool flag=0; for(i=0;i<s.size();i++) { if(s[i]=='0')na++; if(s[i]=='1')nb++; } for(i=0;i<s.size();i++) { flag=0; if(na>a&&s[i]=='0') { ans++;na--; if(nb<b){s[i]='1';nb++;} else s[i]='2'; } else if(nb>b&&s[i]=='1') { ans++;nb--; if(na<a){s[i]='0';na++;} else s[i]='2'; } } for(i=0;i<s.size();i++) if(s[i]=='2') { if(na<a){s[i]='0';na++;ans++;} else if(nb<b){s[i]='1';nb++;ans++;} } cout<<ans<<endl; cout<<s<<endl; } return 0; }