【Codeforces】401C Team (01010110...)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/87097915

http://codeforces.com/contest/401/problem/C

题目中,n表示0的个数,m表示1的个数,要求两个0不能连续,三个1不能连续

还要判断能否输出满足要求的序列,不满足输出-1

满足条件以后徐瑶分情况讨论

当1比0多,且0的个数不为零;

当1的个数等于0的个数;

当1的个数小于0的个数,且1最多只能比0少一个,否则就无法输出。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int zero,one;
	string s;
	cin >> zero >> one;
	if((zero+1)*2<one || zero>one+1) //前者是1多于0 后者是0多于1 
		cout << "-1" << endl;
	else
	{
		while(one + zero)
		{
			if(zero==one+1)//0多 
			{
				s += "0";
				zero--;
			} 
			else if(one>zero && zero>0)//1的个数比0的个数多 
			{
				s += "110"; 
				one-=2;
				zero--;
			}
			else
			{
				s += "1";
				one--;
			}
		}
		cout << s << endl;
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/CSDN___CSDN/article/details/87097915