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. 2.请尝试安装和配置JDK,并给出安装、配置JDK的步骤。

    win10/64位 1.解压jdk1.8.0_91_x64.rar 2.同时按住win键和pause键,弹出系统属性窗口,选择高级系统设计选项. 3.然后单击环境变量按钮. 4.弹出环境变量对话框后, ...

  2. flashbuilder mx组件 MenuBar

    来源:http://www.cuplayer.com/player/PlayerCode/Flex/2013/0118661.html <fx:Script> <![CDATA[ i ...

  3. MySQL 视图 总结

    什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. 数 ...

  4. 暴力+树状数组维护 Codeforces Round #378 (Div. 2) C

    题目大意:给你一个长度为n的数组a,然后数值大的可以合并数值小的,且合并了以后该数组的长度-1.给你一个长度为k目标数组b,问,是否可以从a数组变到b数组,是就yes并且输出步骤.否就输出no 思路: ...

  5. MySql 插入10位以上长度的字符报错or截断

    当a字段为int类型时: 如果用MyBatis向MySql插入10个字符以上长度的字符串,则会报错. 如果直接在MySql中用sql语句插入10个字符以上长度的字符串,则会变成最大的int类型数值:2 ...

  6. ClickOnce发布注意的一些细节

    细节1.应用程序启动前检查更新: 步骤:主工程-右键属性-发布(页面)-按“更新”按钮-勾选“应用程序应该检查更新(T)”-选择“应用程序启动前(F)”,如下图: 细节二:ClickOnce发布时&q ...

  7. NSTimer内存方面的探究

    今天研究一个框架,看到它对NSTimer的处理,感觉很有意思.于是自己在各种情况下都研究了一下,现总结如下. 我们用到NSTimer时,似乎习惯于会在dealloc方法中把它invalidate掉,但 ...

  8. Windows下MySQL分步安装图解及问题总结

    MySQL是一个出色的开源数据库,在易用性和性能方面都有相当不错的表现.就作者发帖为止, MySQL官方发布的所有版本中(4.1/5.0/5.1/6.0),推荐使用稳定的MySQL5.0版本(商用). ...

  9. Sticks<DFS>

    题意: 给n个木棍,这些木棍是由m个长度均为L的木棍切割而来,求L的最小值. 思路: DFS+剪枝. 剪枝: 1:L的取值范围在n(max)和n(sum)之间,逐个枚举.sum%L!=0则L不能用. ...

  10. 转:透析QTP自动化测试框架SAFFRON

    1.为什么要使用框架? 框架是一组自动化测试的规范.测试脚本的基础代码,以及测试思想.惯例的集合.可用于减少冗余代码.提高代码生产率.提高代码重用性和可维护性.例如QTestWare就是QTP自动化测 ...