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. [转载]AngularJS 指令 用法

    http://book.2cto.com/201312/37782.html http://www.itnose.net/detail/6144038.html http://www.cnblogs. ...

  2. [转载]CSS Tools: Reset CSS

    http://meyerweb.com/eric/tools/css/reset/ The goal of a reset stylesheet is to reduce browser incons ...

  3. springMvc + Maven 项目提示 hessian 依赖包 无法下载;

    首先 从 https://github.com/alibaba/dubbo/archive/master.zip 下载最新的 dubbo 源码包到本地某个目录, 解压出来: cmd 进入该目录: 执行 ...

  4. struts与ognl结合【重要】

    -----------------------------ognl表达式------------------------ OGNL:对象视图导航语言.  ${user.addr.name} 这种写法就 ...

  5. web.js

    var page = require('webpage').create(), system = require('system'), address,output,csvPath,nodePathF ...

  6. 004_加速国内docker源下载速度

    docker下载慢的不行.国内加速器地址 http://355dbe53.m.daocloud.iohttps://docker.mirrors.ustc.edu.cn https://hub-mir ...

  7. 通过 EXPLAIN 分析低效 SQL 的执行计划

    每个列的简单解释如下:  select_type:表示 SELECT 的类型,常见的取值有 SIMPLE(简单表,即不使用表连接 或者子查询).PRIMARY(主查询,即外层的查询).UNION(U ...

  8. centos7 部署 docker swarm

    =============================================== 2019/4/9_第3次修改                       ccb_warlock 更新说 ...

  9. java8新特性详解(转)

    原文链接. 前言: Java 8 已经发布很久了,很多报道表明Java 8 是一次重大的版本升级.在Java Code Geeks上已经有很多介绍Java 8新特性的文章,例如Playing with ...

  10. ACM-ICPC 2018年北京网络赛 D-80 days

    题意: n个城市环形连接,初始有c的钱,每到i城市,会获得a[i]的金钱,失去b[i]的金钱,问能否走遍这n个城市,且过程中金钱不为负数,输出起始城市,如果答案有多个,输出最小的数字. 思路:a[i] ...