【CF 708B】Recover the String(组合+瞎搞)

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For each string s consisting of characters ‘0’ and ‘1’ one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x, y}.

In these problem you are given four integers a00, a01, a10, a11 and have to find any non-empty string s that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than 1 000 000.

Input

The only line of the input contains four non-negative integers a00, a01, a10 and a11. Each of them doesn’t exceed 109.

Output

If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print “Impossible“. The length of your answer must not exceed 1 000 000.

Examples
Input
1 2 3 4
Output
Impossible
Input
1 2 2 1
Output
0110

这场打的……岂一个惨字了得……

这题除了手残没别的问题……,,。。

意思是给出四个参数
a00 表01串中00对的数量
a01 表01串中01对的数量
a10 表01串中10对的数量
a11 表01串中11对的数量

譬如01010 a00=2  a01=3  a10=3  a11=1

输出四个参数严格等于给定参数的01串,不存在则输出Impossible

不难想到,由 a00a11 可以确定0和1的数量,定义为 c0 c1
则一定满足
c0(c01)2==a00
c1(c11)2==a11

需要特判 a00 a11 为0的情况,此时0或1可以有1个或者没有。

先考虑一般情况,需要搞定的就是确定0和1的摆放顺序。
假定把1全放在右边,0全放在左边,那么 a01=0  a10=c0c1
然后我们在随意移动1,可以发现不管移动哪几个位置,不管当前状态如何,在合法移动的情况下,把1向右移动,如果右边是1不会影响,是0的话,一定会导致 a01++    a10
换句话说,如果能构出合法的01串的话, a01a10 的加和是固定的,为 c0c1

那么在上面等式成立的状态下,只要保证两个中的一个参数满足要求,另一个就一定满足要求。

那就按要求摆,用一个变量k表示剩余未摆的1的个数,那么如果当前位置放0, a01 就会增加k,看一下是否超出当前需要的01的个数,然后贪心摆就好。

至于 a00 a11 为0的情况,特殊搞一下就行了。BUT!赛时就WA在这了……手癌写反了。。。。。。。。。。。。。

代码如下:

#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define VI vector<int>
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)

using namespace std;
const int INF = 0x3f3f3f3f;
const int msz = 10000;
const int mod = 1e9+7;
const double eps = 1e-8;

char str[1111111];

int main()
{
    //fread("in.in");
    //fread("out.out");

    int a,b,c,d;
    int len = 0;

    scanf("%d%d%d%d",&a,&b,&c,&d);
    int k,r;

    k = r = 1;

    //找到c0 c1
    while(k*(k-1)/2 < a) ++k;
    while(r*(r-1)/2 < d) ++r;

    if(k*(k-1)/2 != a || r*(r-1)/2 != d)
    {
        puts("Impossible");
        return 0;
    }

    bool f = 1;

    //a00 a11均为0
    if(a == 0 && d == 0)
    {
        if(b == 0 && c == 0) puts("0");
        else if(b == 0 && c == 1) puts("10");
        else if(b == 1 && c == 0) puts("01");
        else puts("Impossible");
        return 0;
    }
    else if(a == 0)//a00为0 串中可有1个0或者没有
    {
        if(b == 0 && c == 0) 
        {
            while(r--) str[len++] = '1';
        }
        else if(b+c == r)//10+01 == 1的个数 构成1111011这种
        {
            while(c--) str[len++] = '1';
            str[len++] = '0';
            while(b--) str[len++] = '1';
        }
        else f = 0;
    }
    else if(d == 0)//a11为0 串中可有1个1或者没有
    {
        if(b == 0 && c == 0) 
        {
            while(k--) str[len++] = '0';
        }
        else if(b+c == k)//01+10 == 0的个数 构成0000100这种
        {
            while(b--) str[len++] = '0';
            str[len++] = '1';
            while(c--) str[len++] = '0';
        }
        else f = 0;
    }
    else
    {
        if(b+c == k*r)//a01+a10 == c0*c1
        {
            while(b)//优先构a01 (先构10也行
            {
                while(r > b)//剩余1的个数 > 剩余需要01的个数
                {
                    str[len++] = '1';
                    --r;
                }
                str[len++] = '0';
                --k;
                b -= r;
            }

            //此时01已构完
            while(r--) str[len++] = '1';
            while(k--) str[len++] = '0';
        }
        else f = 0;
    }

    if(!f)
    {
        printf("Impossible");
        return 0;
    }
    str[len] = 0;
    puts(str);

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
DB历史主题丢失是指数据库历史记录的主题内容不见了。这种情况下,我们可以尝试通过重新配置来恢复它。 首先,我们需要检查数据库配置文件,确保历史记录功能没有被禁用或配置错误。检查配置文件中与历史记录相关的参数设置,如历史记录的保留时间、历史记录文件的存储位置等。如果这些参数设置正确,但历史主题仍然丢失,我们可以尝试以下步骤进行恢复。 1. 停止数据库服务:首先,需要停止正在运行的数据库服务,以便执行下一步的操作。 2. 备份数据库:在进行任何恢复操作之前,务必先备份数据库文件,以防止意外数据丢失。 3. 清空历史记录相关文件:进入数据库目录,并删除与历史记录相关的文件,如历史记录日志文件、历史记录索引文件等。这样做的目的是清除之前可能存在的损坏的历史记录文件。 4. 重新配置数据库:编辑数据库配置文件,重新启用历史记录功能并确保相应的参数设置正确。 5. 启动数据库服务:保存更改后,重新启动数据库服务,让新的配置生效。 6. 监视恢复进程:在数据库启动后,我们可以通过监视日志或使用数据库管理工具,验证历史记录是否被正确恢复。可以查看历史记录是否开始重新生成,以及检查历史记录文件是否存在以及大小是否与预期一致。 7. 测试恢复结果:使用数据库客户端连接到数据库,并执行一些操作,以验证历史记录是否正常工作。可以查询历史记录文件,查看相应的操作是否已被记录。 总之,当DB历史主题丢失时,我们可以尝试通过重新配置数据库来恢复它。这个过程需要注意备份数据、重要文件的清除和重新配置以及验证恢复结果等步骤,以确保恢复过程顺利且有效。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值