Recover the String
Recover the String
题目链接:http://codeforces.com/contest/709/problem/D
构造
这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1'的个数n0和n1,就很好构造了:
1.将整个字符串填满'1',在所有的1右边填x个'0',那么'10'就有x*n1个了,一直填到还需要'10'的个数t1小于n1个;
2.再从右边数n1-t1个'1'并在它前面添加一个'0';
3.删去多余的'1'.
如此看来,构造并不困难,难的是判断何时Impossible.我们可以看到a1和a4必须是(1+n)*n/2的形式,而a2+a3肯定等于n0*n1(对于每一个'1',若左边有x个'0',那么右边有n0-x个'0')。但是这样直接交还会WA,还有一种情况没有考虑:只有'1'或只有'0'的情况,这种情况特判就好啦。
代码如下:
#include<cstdio>
#include<cmath>
using namespace std;
int a,b,c,d;
char s[];
int main(void){
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a+b+c+d==){
printf("1\n");
return ;
}
int n0=(int)sqrt(*a)+;
if(n0*(n0-)/!=a){
printf("Impossible\n");
return ;
}
int n1=(int)sqrt(*d)+;
if(n1*(n1-)/!=d){
printf("Impossible\n");
return ;
}
if(n0+n1>){
printf("Impossible\n");
return ;
}
if(c+b+d==){
for(int i=;i<n0;++i)
printf("");
printf("\n");
return ;
}else if(a+b+c==){
for(int i=;i<n1;++i)
printf("");
printf("\n");
return ;
}
if((c+b)!=n0*n1){
printf("Impossible\n");
return ;
}
for(int i=;i<n0+n1;++i)
s[i]='';
int t=c/n1;
for(int i=;i<t;i++)
s[n0+n1--i]='';
int t1=c-t*n1;
int k=,i;
for(i=n0+n1-;i>=;--i){
if(k==n1-t1){
s[i]='';
break;
}
if(s[i]=='')k++;
}
for(;i>=;--i){
if(s[i]=='')k++;
if(k>n1)s[i]='';
}
printf("%s\n",s);
}
Recover the String的更多相关文章
- codeforces 709D D. Recover the String(构造)
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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 ...
- 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 ...
- 【CodeForces】708 B. Recover the String 数学构造
[题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...
- B. Recover the String
B. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 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 ...
- CF708B Recover the String 构造
For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 an ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- CodeForces 708B Recover the String
构造. 根据$a[0][0]$可以求得$0$的个数$p$,根据$a[1][1]$可以求得$1$的个数$q$. 如果找不到$p$或$q$,那么就无解. 每一个$0$放到序列中的任何一个位置,假设和前面的 ...
随机推荐
- jsp-2 简单的servlet连接mysql数据库 增删改查
连接mysql数据库的操作 有增删改查 用的包有 commons-lang3-3.5 mysql-connector-java-5.1.40-bin 但是实际上也就是 数据查询和数据处理两种 所以对数 ...
- div、span
1.Html区块元素 HTML可以通过<div>和<span>将元素组合起来 大多数HTML元素被定义为块级元素或内联元素, 而块级元素在浏览器显示时,通常会以新行来开始(或结 ...
- Linux中的info指令
Info 是什么?info是一种文档格式,也是阅读此格式文档的阅读器:我们常用它来查看Linux命令的info文档.它以主题的形式把几个命令组织在一起,以便于我们阅读:在主题内以node(节点)的形式 ...
- Array类型方法总结(未写完)
转换方法: toString() toLocaleString() valueOf() 栈方法: push()---在数组末尾添加项,返回修改后的长度, pop()---在数组末尾移除项,返 ...
- PostgreSQL 序列使用
数据库中主键的生成一般是通过序列来生成,PG的序列知识主要罗列如下: 如何找到序列的名称:用pgadmin打开当前所用数据库,在schemas->sequences下找到相关的序列,然后SELE ...
- Java中修饰符
下面这张图应该大家都见过,根据图表来记忆最好理解 范围 private friendly(默认) protected public 当前类 √ √ √ √ 当前包中的类 √ √ √ 当前包中的类, ...
- CentOS7配置OpenCV2.4.13
以管理员身份运行su root输入密码 安装依赖包 yum install gcc gcc-c++ gtk2-devel gimp-devel gimp-devel-tools gimp-help-b ...
- 如何使用jconsole(英文)
http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html
- 转:NSString什么时候用copy,什么时候用strong
大部分的时候NSString的属性都是copy,那copy与strong的情况下到底有什么区别呢? 比如: @property (retain,nonatomic) NSString *rStr; @ ...
- Hadoop集群出现no data node to stop的解决方案
问题描述: 今天stop hadoop集群的时候出现no datanode to stop ,寻找解决方案,并不是网上资料所说的什么DFS Used .Non DFS Used等于0 .所有的节点都是 ...