D. 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 exceed109.

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

比赛时,一直纠结怎么判断Impossible和构造字符串,胡乱交了一发,wa了,好SB。

当然先是利用a00和a11求1和0的字符串个数g1和g0,如果a00或a11等于1,这时候还要根据a10和a01判断a00或者a11是等于1还是0.

在求完a00和a11的个数后,判断合不合理,C(g0,2)=a00, C(g1,2)=a11, C(g1+g0,2) = a00+a01+a10+a11即成立。

然后就是构造字符串了。

设初始的字符串个数为0000001111111......

然后就是贪心的构造字符串了。考虑该输出某一位时,如果在这一位时,a10>=g0,那么我可以把1挪到最前面,输出1,这时候后面剩下的字符串需要构造的a10-=g0,剩余的1的个数g1--。否则直接输出0,后面剩余字符串需要构造a01-=g1,剩余的0的个数g0--.

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
ll a00,a01,a10,a11;
scanf("%I64d%I64d%I64d%I64d",&a00,&a01,&a10,&a11);
ll g0,g1;
g0 = (+sqrt(+*a00))/;
g1 = (+sqrt(+*a11))/;
if(a00+a01+a10+a11==)
{
printf("0\n");
return ;
}
if(g0==||g1==)
{
if(g0==)
{
if(a01||a10) g0 = ;
else g0 = ;
}
if(g1==)
{
if(a01||a10) g1 = ;
else g1 = ;
}
}
if(g0*(g0-)!=*a00||g1*(g1-)!=*a11)
{
printf("Impossible\n");
return ;
}
ll gz = g0+g1;
if(gz*(gz-)/!=(a00+a01+a10+a11))
{
printf("Impossible\n");
return ;
}
while(g0+g1)
{
if(a10>=g0)
{
printf("");
a10 -= g0;
g1--;
}
else
{
printf("");
a01 -= g1;
g0--;
}
}
printf("\n");
return ;
}

AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)的更多相关文章

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

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

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

  3. AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心

    A. Letters Cyclic Shift 题目连接: http://www.codeforces.com/contest/708/problem/A Description You are gi ...

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

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

  6. 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}$ 挺简单的构造, 注意到可以通 ...

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

  8. AIM Tech Round 3 (Div. 2)

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

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

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

随机推荐

  1. hdu_5620_KK's Steel(水题)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5620 题意:给你一个n长的钢管,要分的尽可能多,且任意三条不能构成三角形 题解:看hint就知道用递推 ...

  2. 一个forward_list C++primer

    #include<iostream> #include<forward_list> using namespace std; int main() { forward_list ...

  3. OPENWRT make defconfig错误之一

    make defconfig rm: cannot remove `tmp/.host.mk': Permission denied 退到trunk上级目录 su root sudo chown -R ...

  4. 模拟摇奖:从1-36中随机抽出8个不重复的数字(math)

    public class Yaojiang { public static void main(String[] args) { // TODO 自动生成的方法存根 int[] a=new int[8 ...

  5. php:sprintf

    十六进制 $hex = sprintf("%x",18); 输出:12(%x表示十六进制) $hex = sprintf("%4x",18); 输出:strin ...

  6. mvc页面中,显示自定义时间格式

    1.在model中,遇到datetime格式的字段,用string来表示 model中 /// <summary> /// 开始时间 /// </summary> [Displ ...

  7. ubuntu 自动获取ip的怎么设置

    ubuntu以DHCP方式配置网卡自动获取ip编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces并用下面的行来替换有关eth0的行: ...

  8. 转 Oracle 12C 之 CDB/PDB用户的创建与对象管理

    在Oracle 12C中,账号分为两种,一种是公用账号,一种是本地账号(亦可理解为私有账号).共有账号是指在CDB下创建,并在全部PDB中生效的账号,另一种是在PDB中创建的账号. 针对这两种账号的测 ...

  9. HDU 5652 India and China Origins 二分优化+BFS剪枝

    题目大意:给你一个地图0代表可以通过1代表不可以通过.只要能从第一行走到最后一行,那么中国与印度是可以联通的.现在给你q个点,每年风沙会按顺序侵蚀这个点,使改点不可通过.问几年后中国与印度不连通.若一 ...

  10. setter getter 属性 点语法

    转载自:http://liuyafang.blog.51cto.com/8837978/1543715 什么时setter,getter, 在OC里, 为实例变量赋zhi的方法称作setter(设置器 ...