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. Java日期比较

    在进行业务处理时,遇到一个需要比较日期但是不包含时分秒的判断问题 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); ...

  2. poj 2438 Children's Dining

    http://poj.org/problem?id=2438 题意: 有2*N个人要坐在一张圆桌上吃饭,有的人之间存在敌对关系,安排一个座位次序,使得敌对的人不相邻. 假设每个人最多有N-1个敌人.如 ...

  3. django+mysql安装和设置

    之前我们已经用sqlite建立了第一个web app.今天来学习如何在django中使用MySQL. 首先需要安装MySQL,到官网下载安装包:https://dev.mysql.com/downlo ...

  4. Linux 定时器应用【转】

    Linux 定时器应用 实验目的 阅读 Linux 相关源代码,学习 Linux 系统中的时钟和定时器原理,即,ITIMER_REAL实时计数,ITIMER_VIRTUAL 统计进程在用户模式执行的时 ...

  5. 底板芯片组与内存映射(Motherboard Chipsets and the Memory Map) 【转】

    转自:http://blog.chinaunix.net/uid-25909619-id-4194650.html 底板芯片组与内存映射 我打算写一些关于计算机内部构造(computer intern ...

  6. TFS报表管理器无权限访问的配置

    刚接触TFS,有太多的功能不能知道怎么配置,今天想了解一下TFS的报表功能,当登录TFS后,点击项目中的“查看报表”

  7. 谈谈如何查看Android项目方法数

    我们都知道,Android App的方法数是有天花板的,在方法数达到65536时,就会出现打包异常,这个时候,我们需要去除一些不需要的三方工具包,或者采用多Dex技术分包,都能达到正常打包的效果. 可 ...

  8. Android 拍摄(横\竖屏)视频的懒人之路

    想一想,我们聊过AudioReord,AudioTrack,MediaPlayer,那多媒体四大金刚,就剩下了MediaRecorder了(SoundPool?我这里信号不好···).其实MediaR ...

  9. JavaEE 学习框架

    JavaSE JavaWeb基础 ssh+hibernate+spring ssm+spring+mybatis 项目1 电商项目(项目二)

  10. SP14932 【LCA - Lowest Common Ancestor】

    专业跟队形 唯一一个有$\LaTeX$的 裸的$LCA$,我用的是$Tarjan~LCA$,注意两点相同特判 #include<iostream> #include<cstdio&g ...