本文主要是介绍【字符串模拟】Binary String Constructing,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
7/31下午暑假训练1的题解(Codeforces Round #496 (Div. 3))【CF1003B】
公式会有乱码,我就直接粘贴图片了。
Examples
Input
2 2 1
Output
1100
Input
3 3 3
Output
101100
Input
5 3 6
Output
01010100
Note
All possible answers for the first example:
- 1100;
- 0011.
All possible answers for the second example:
- 110100;
- 101100;
- 110010;
- 100110;
- 011001;
- 001101;
- 010011;
- 001011.
刚开始理解错了题意,以为要求是不仅有X个不同的01组合相邻还要求在第X个位置上也相邻,WA了好多次之后重新读题,然后重写了代码,就过了,读题一定要慢和细心,磨刀不负砍柴工。
#include <iostream>
#include <string>
using namespace std;
int main()
{int a,b,x,n;char c,d;cin>>a>>b>>x;n=a+b;if(a>b) c='0',d='1';else {c='1',d='0';swap(a,b);}string ans;for(int i=0;i<x/2;i++){ans+=c;a--;ans+=d;b--;}if(x%2==0){while(b--) ans+=d;while(a--)ans+=c;}else{while(a--) ans+=c;while(b--) ans+=d;}
cout<<ans<<endl;return 0;
}
这篇关于【字符串模拟】Binary String Constructing的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!