B. 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 ofsubsequences 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 than1 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

思路:根据a[0]和a[3],我们可以解出0,1的个数x1,x2,开始先按照前面全是0后面全是1来排列这个时候我们可以知道01的个数就是x1*x2,然后我们发现当0向右移位的时候,没超过一个1的时候01个数少1,10个数多1,那么我们知道,01和10的个数之和就是x1*x2,这样可以判断是否有解,然后就是到底咋移,因为可以一个一个增加,所以贪心,每次移一个,然后移动具体看代码;

  1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<queue>
7 #include<set>
8 #include<math.h>
9 #include<vector>
10 using namespace std;
11 typedef long long LL;
12 LL a[5];
13 short int ans[1000005];
14 bool check(LL n);
15 int main(void)
16 {
17 while(scanf("%I64d",&a[0])!=EOF)
18 {
19 int i,j;
20 for(i = 1; i < 4; i++)
21 {
22 scanf("%I64d",&a[i]);
23 }
24 LL x1 = 1+8*a[0];
25 LL x2 = 1+8*a[3];
26 bool fla1 = check(x1);
27 bool fla2 = check(x2);
28 if(!fla1||!fla2)
29 {
30 //printf("1\n");
31 printf("Impossible\n");
32 }
33 else
34 {
35 if(a[0]==0&&a[1]==0&&a[2]==0&&a[3]==0)
36 {
37 printf("1\n");
38 }
39 else if(a[0]!=0&&a[1]==0&a[2]==0&&a[3]==0)
40 {
41 LL cnt = 1+sqrt(1+8*a[0]);
42 cnt/=2;
43 for(i = 0; i <cnt ; i++)
44 printf("0");
45 printf("\n");
46 }
47 else if(a[0]==0&&a[1]==0&&a[2]==0&&a[3]!=0)
48 {
49 LL cnt = sqrt(1+8*a[3])+1;
50 cnt/=2;
51 for(i = 0 ; i < cnt ; i++)
52 printf("1");
53 printf("\n");
54 }
55 else
56 {
57 x1 = 1 + sqrt(x1);
58 x1/=2;
59 x2 = 1 + sqrt(x2);
60 x2/=2;
61 fill(ans,ans+1000005,1);
62 LL sum1 = x1*x2;
63 LL sum2 = 0;
64 if(sum1 != a[1]+a[2])
65 printf("Impossible\n");
66 else
67 {
68 LL ac = a[2];
69 LL ak = ac/x2;
70 LL tt = ac%x2;
71 LL nn = x1 + x2;
72 if(tt) ak++;
73 for(i = 0; i < (x1-ak); i++)
74 {
75 printf("0");
76 }
77 if(tt == 0)
78 {
79 for(i = 0; i < x2 ; i++)
80 printf("1");
81 }
82 else
83 {
84 for(i = 0; i < x2 ; i++)
85 {
86 if(i == tt)
87 printf("0");
88 else printf("1");
89 }
90 printf("1");
91 }
92 if(tt)ak--;
93 for(i = 0 ; i < ak ; i++)
94 {
95 printf("0");
96 }
97 printf("\n");
98 }
99 }
100 }
101 }
102 return 0;
103 }
104 bool check(LL n)
105 {
106 LL ap = sqrt(1.0*n);
107 if(ap*ap == n)
108 return true;
109 return false ;
110 }

B. Recover the String的更多相关文章

  1. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. Recover the String

    Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...

  3. 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 ...

  4. AIM Tech Round 3 (Div. 1) B. Recover the String 构造

    B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each str ...

  5. 【CodeForces】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  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. CF708B Recover the String 构造

    For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 an ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. CodeForces 708B Recover the String

    构造. 根据$a[0][0]$可以求得$0$的个数$p$,根据$a[1][1]$可以求得$1$的个数$q$. 如果找不到$p$或$q$,那么就无解. 每一个$0$放到序列中的任何一个位置,假设和前面的 ...

随机推荐

  1. binlog真的是银弹吗?有些时候也让人头疼

    大家好,我是架构摆渡人.这是实践经验系列的第三篇文章,这个系列会给大家分享很多在实际工作中有用的经验,如果有收获,还请分享给更多的朋友. binlog 用于记录用户对数据库操作的SQL语句信息,同时主 ...

  2. 日常Java 2021/10/26

    HashSet基于HashMap来实现的,是一个不允许有重复元素的集合.HashSet 允许有null 值. HashSet是无序的,即不会记录插入的顺序. HashSet不是线程安全的,如果多个线程 ...

  3. 【Go语言学习笔记】包

    包其实是每个大型工程都会使用的模块化工具. 将相关的代码封装成一个包,给其他项目调用,提供不同的功能. GO的设计是将一个文件夹看成一个包,虽然不一定非要用文件夹的名字,但是比较建议. 同一个文件夹下 ...

  4. day02 web主流框架

    day02 web主流框架 今日内容概要 手写简易版本web框架 借助于wsgiref模块 动静态网页 jinja2模板语法 前端.web框架.数据库三种结合 Python主流web框架 django ...

  5. Spark基础:(三)Spark 键值对操作

    1.pair RDD的简介 Spark为包含键值对类型的RDD提供了一些专有的操作,这些RDD就被称为pair RDD 那么如何创建pair RDD呢? 在不同的语言中有着不同的创建方式 在pytho ...

  6. notepad++ 连接远程服务器

    前言:为了便于编辑 linux 上的文件,因此通过 notepad++ 连接服务器后打开,编辑完,保存即可 1. 打开 notepad++,安装插件 2. 搜索 NppFtp,找到后 点击 安装/in ...

  7. 【力扣】649. Dota2 参议院

    Dota2 的世界里有两个阵营:Radiant(天辉)和 Dire(夜魇) Dota2 参议院由来自两派的参议员组成.现在参议院希望对一个 Dota2 游戏里的改变作出决定.他们以一个基于轮为过程的投 ...

  8. 第三届“传智杯”全国大学生IT技能大赛(初赛A组)题解

    留念 C - 志愿者 排序..按照题目规则说的排就可以.wa了两发我太菜了qwq #include<bits/stdc++.h> using namespace std; const in ...

  9. Mysql脚本 优化检测

    下载地址: wget https://launchpad.net/mysql-tuning-primer/trunk/1.6-r1/+download/tuning-primer.sh 安装依赖: y ...

  10. Python绘制饼图

    Python绘制饼图 1.1 对应代码如下图所示 import matplotlib.pyplot as pltfrom pylab import mplmpl.rcParams['font.sans ...