B. Recover the String

题目连接:

http://www.codeforces.com/contest/708/problem/B

Description

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.

Sample Input

1 2 3 4

Sample Output

Impossible

Hint

题意

你要构造一个只含有01的串,其中子序列:00有a个,01有b个,10有c个,11都d个。

如果不能,输出impossible

题解:

通过00和11,我们知道这个串里面0和1分别有多少个,然后我们就可以构造了。

假设0全部放在前面,1全部放在后面,那么如果把一个1扔到最前面,那么C就会减去当前0的个数。

然后我们就通过这个玩意儿去构造就好了。

代码

#include<bits/stdc++.h>
using namespace std; long long f(long long x)
{
return x*(x-1)/2;
}
long long a,b,c,d,A,B;
int flag=0;
int main()
{
cin>>a>>b>>c>>d;
for(long long i=0;f(i)<=a;i++)
{
if(f(i)==a)
{
for(long long j=0;f(j)<=d;j++)
{
if(f(j)==d)
{
if(i*j==b+c)
{
A=i;
B=j;
flag=1;
}
}
}
}
}
if(flag==0)
return puts("Impossible"),0;
if(A==0&&B==0)
return puts("Impossible"),0;
int sum = A+B;
for(int i=0;i<sum;i++)
{
if(c>=A)
{
B--;
c-=A;
printf("1");
}
else
{
A--;
printf("0");
}
}
printf("\n");
return 0;
}

AIM Tech Round 3 (Div. 1) B. Recover the String 构造的更多相关文章

  1. AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)

    D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. CF AIM Tech Round 3 (Div. 2) D - Recover the String

    模拟 首先可以求出 0 和 1 的个数 之后按照01 10 的个数贪心安排 细节太多 错的都要哭了 #include<bits/stdc++.h> using namespace std; ...

  3. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  4. AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)

    rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...

  5. AIM Tech Round 3 (Div. 1) (构造,树形dp,费用流,概率dp)

    B. Recover the String 大意: 求构造01字符串使得子序列00,01,10,11的个数恰好为$a_{00},a_{01},a_{10},a_{11}$ 挺简单的构造, 注意到可以通 ...

  6. codeforces708b// Recover the String //AIM Tech Round 3 (Div. 1)

    题意:有一个01组成的串,告知所有长度为2的子序列中,即00,01,10,11,的个数a,b,c,d.输出一种可能的串. 先求串中0,1的数目x,y. 首先,如果00的个数a不是0的话,设串中有x个0 ...

  7. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  8. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  9. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...

随机推荐

  1. [iOS]图片高清度太高, 导致内存过大Crash

    先说一下状况, 后台提供的图片太高清了, 每个图片都在2-4MB, iOS上每个页面需要同时下载并展示10-15张. 这个时候, 如果我多滑动collectionView几次, 直接App就崩溃了(r ...

  2. 兼容 IE6+ 获取图片大小

    昨天说了 HTML5 的file对象可以获取到文件的 文件名,文件大小,文件类型,最后一次修改日期.其实 IE6-9 也可以变向的获取到,虽然没那么方便,但至少可以取到.来看例子吧: <!doc ...

  3. jq无缝滚动效果插件(之前的那个升级改造加强版)

    scroll滚动插件 支持上下左右,淡入淡出,滚动时间设置,动画时间设置,鼠标经过是否停止设置 默认配置参数可修改 $(".content").easysroll({ //默认配置 ...

  4. 【51Nod】1510 最小化序列 贪心+动态规划

    [题目]1510 最小化序列 [题意]给定长度为n的数组A和数字k,要求重排列数组从而最小化: \[ans=\sum_{i=1}^{n-k}|A_i-A_{i+k}|\] 输出最小的ans,\(n \ ...

  5. HDU 2049 不容易系列之(4)——考新郎 (错排+组合)

    题目链接. Problem Description 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体 ...

  6. xml json

    简单概括的话就是,xml本身是一种格式规范,是一种包含了数据以及数据说明的文本格式规范. 比如,我们要给对方传输一段数据,数据内容是“too young,too simple,sometimes na ...

  7. py-faster-rcnn代码阅读2-config.py

    简介  该文件指定了用于fast rcnn训练的默认config选项,不能随意更改,如需更改,应当用yaml再写一个config_file,然后使用cfg_from_file(filename)导入以 ...

  8. mybatis输入输出映射——(五)

    0.#{}与${}区别 #{}实现的是向prepareStatement中的预处理语句中设置参数值,sql语句中#{}表示一个占位符即?. <!-- 根据id查询用户信息 --> < ...

  9. 对linux内核中jiffies+Hz表示一秒钟的理解

    jiffies在内核中是一个全局变量,它用来统计系统启动以来系统中产生的总节拍数,这个变量定义在include/linux/jiffies.h中,定义形式如下. unsigned long volat ...

  10. Spring bean 配置

    1.传统的创建对象的方式:JedisMall tardition=new JedisMall(); 这样是在程序运行时创建,表示当前模块已经不知不觉和new出的对象耦合了,而我们通常都是更高层次的抽象 ...