题目很好推 00的个数推0的个数 11的个数推1的个数 如果存在那么就判断四个数的合是否为 C(0和1的总个数,2)如果存在有解贪心一下就行即根据第二个数值和1的位置固定然后叉进0最后使其成立
有个超级坑的就是00或11的个数 是0时那0或1的个数是0 或者是1要特殊判断!!!!
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 1000005
#define LL long long
using namespace std;
LL am[maxn];
LL a, b, c, d;
LL bin(LL a)
{
LL l = 1, r = 1000001, ans = -1;
for(LL i = 0; i <= 1000001; i++)
if(i * (i - 1) == 2 * a) return i;
return ans;
}
int main()
{
scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d);
LL am1 = bin(a), am2 = bin(d);
//特判代码
if(am1 == 0 && am2 == 0)
{
if(2 * (a + b + c + d) == (am1 + 1 + am2) * (am1 + am2))am1++;
else if(2 * (a + b + c + d) == (am1 + 2 + am2) * (am1 + 1 + am2)){ am1++; am2++;}
}
else if(am1 == 0) {if(2 * (a + b + c + d ) == (am1 + 1 + am2) * (am1 + am2))am1++;}
else if(am2 == 0)
{
if(2 * (a + b + c + d) == (am1 + 1 + am2) * (am1 + am2))am2++;
}
//-----------------------------------------------------------------
if(am1 == -1 || am2 == -1) printf("Impossible\n");
else if(a + b + c + d != (am1 + am2) * (am1 + am2 - 1) / 2) printf("Impossible\n");
else if(a + b + c + d == 0)printf("1\n");
else
{
LL pre = b;
for(int i = 1; i<= am1; i++)
{
LL pre2 = min(am2, pre);
am[am2 - pre2 + 1]++;
pre -= pre2;
}
for(int i = 1; i <= am2; i++)
{
for(int j = 0; j < am[i]; j++)printf("0");
printf("1");
}
for(int j = 0; j < am[am2 + 1]; j++)printf("0");
}
return 0;
}