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 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 构造的更多相关文章
- 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 ...
- CF AIM Tech Round 3 (Div. 2) D - Recover the String
模拟 首先可以求出 0 和 1 的个数 之后按照01 10 的个数贪心安排 细节太多 错的都要哭了 #include<bits/stdc++.h> using namespace std; ...
- 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 ...
- 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 ...
- 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}$ 挺简单的构造, 注意到可以通 ...
- 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 ...
- AIM Tech Round 3 (Div. 2)
#include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...
- AIM Tech Round 3 (Div. 2) A B C D
虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...
- AIM Tech Round 3 (Div. 2) B
Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...
随机推荐
- javascript设计模式开篇:Javascript 接口的实现
javascript语言不像java. c#. c++等面向对象语言那样有完备的接口支持,在javascript中,接口的实现有三种方式,分别为注释描述.属性检查.鸭式变形.注释描述实现起来最为简单, ...
- iOS 根据生日得到生肖,星座,年龄的算法
根据用户生日,得到相应的年龄,星座和生肖.有的项目中可能会用到,贴出来共享. 得到年龄,这个很简单了: - (void)getAgeWith:(NSDate*)birthday{ //日历 NSCal ...
- input同名
form表单传值,当,input的 name相同时候,可以同时传值. 当你提交时,你获取的同name数据会被后加载的那个input替代.容易造成数据混乱,但是,可以在某些特殊情况使用.比如,selec ...
- 第5月第8天 jsonmodel
1. @implementation JSONValueTransformer (CustomTransformer) //时间戳转NSDate - (NSDate *)NSDateFromNSStr ...
- 转载 python多重继承C3算法
备注:O==object 2.python-C3算法解析: #C3 定义引用开始 C3 算法:MRO是一个有序列表L,在类被创建时就计算出来. L(Child(Base1,Base2)) = [ Ch ...
- 洛谷 P4128: bzoj 1815: [SHOI2006]有色图
题目传送门:洛谷 P4128. 计数好题,原来是 13 年前就出现了经典套路啊.这题在当年应该很难吧. 题意简述: \(n\) 个点的完全图,点没有颜色,边有 \(m\) 种颜色,问本质不同的图的数量 ...
- git学习——Git 基础要点【转】
转自:http://blog.csdn.net/zeroboundary/article/details/10549555 简单地说,Git 究竟是怎样的一个系统呢?请注意,接下来的内容非常重要,若是 ...
- mysql双主+keepalived【转】
简单原理 1.在两台服务器上分别部署双主keepalived,主keepalived会在当前服务器配置虚拟IP用于mysql对外提供服务 2.在两台服务器上分别部署主主mysql,用于故障切换 3.当 ...
- 搜索引擎ElasticSearchV5.4.2系列二之ElasticSearchV5.4.2+kibanaV5.4.2+x-packV5.4.2安装
相关博文: 搜索引擎ElasticSearchV5.4.2系列一之ES介绍 搜索引擎ElasticSearchV5.4.2系列二之ElasticSearchV5.4.2+klanaV5.4.2+x-p ...
- 数据库SQL语句性能优化
选择最有效率的表名顺序 ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处理,在FROM子句中包含多个表的情况下 ...