模拟

 

umbled String

Kattis - jumbledstring

Recall that a subsequence of a string is any string obtained by removing some subset of characters from the string, for instance “string”, “sing”, “i” and “sg” are all subsequences of “string”. If the same subsequence can be obtained in exactly t different ways, by removing different subsets of characters, we say that the subsequence occurs t times.

Jingfei wants to create a nonempty bit string that has the following properties:

  1. the subsequence 00 occurs a

  • times,

  • the subsequence 01 occurs b

  • times,

  • the subsequence 10 occurs c

  • times, and

  • the subsequence 11 occurs d

  1. times.

However, Jingfei does not know how to create such a string – or whether it is even possible. Could you help her?

Input

The input consists of a single line with four integers a

, b, c, and d (0≤a,b,c,d≤109

).

Output

Output a bit string that satisfies the given requirements. If there are several solutions, output any one of them. If there are no solutions, output “impossible”.

Sample Input 1Sample Output 1
3 4 2 1
01001
Sample Input 2Sample Output 2
5 0 0 5
impossible
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
bool fdas(int a, ll &aa)
{
    if(a==0)
    {
        aa=1;
//        return true;
    }
    else
    {
        ll sum=0;
        int i=1;
        while(i)
        {
            sum+=i;
            if(sum==a)
            {
                aa=i+1;
                break;
            }
            if(sum>a)
            {
                return false;
            }
            i++;
        }
//         if((a/2)*(a/2+1)==a)
//           aa=a/2;
//        else
//           return false;


    }
    return true;

}
int main()
{
    int a, b, c, d;
    while(scanf("%d%d%d%d", &a, &b, &c, &d)!=EOF)
    {
        ll aa, dd;
        if(a==0&&b==0&&c==0)
        {
            if(fdas(d, dd))
            {
                for(ll i=0; i<dd; i++)
                {
                    printf("1");
                }
                printf("\n");
            }
            else
            {
                printf("impossible\n");
            }
            continue;
        }
        if(d==0&&b==0&&c==0)
        {
            if(fdas(a, aa))
            {
                for(ll i=0; i<aa; i++)
                {
                    printf("0");
                }
                printf("\n");
            }
            else
            {
                printf("impossible\n");
            }
            continue;
        }
        if(a==0&&b==1&&c==0&&d==0)
        {
            printf("01\n");
            continue;
        }
        if(a==0&&b==0&&c==1&&d==0)
        {
            printf("10\n");
            continue;
        }
        if(fdas(a, aa)&&fdas(d, dd))
        {
            ll w=b/aa;
            ll z=b-w*aa;
            int e=1;
            if(z==0)   //感觉很强
            {
                e=0;
            }
            if((dd-w-e)*aa+e*(aa-z)!=c)
            {
                printf("impossible\n");
                continue;
            }
            for(ll i=0; i<dd-w-e; i++)
            {
                printf("1");
            }
            for(ll i=0; i<z; i++)
            {
                printf("0");
            }
            if(e)
            {
                printf("1");
            }
            for(ll i=0; i<aa-z; i++)
            {
                printf("0");
            }
            for(ll i=0; i<w; i++)
            {
                printf("1");
            }
            printf("\n");
        }
        else
        {
            printf("impossible\n");
            continue;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

z6q6k6

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值