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$放到序列中的任何一个位置,假设和前面的 ...
随机推荐
- asp.net core + mysql + ef core + linux
asp.net core + mysql + ef core + linux 以前开发网站是针对windows平台,在iis上部署.由于这次需求的目标服务器是linux系统,就尝试用跨平台的.NET ...
- MVC源码解析 - Http Pipeline 解析(下)
接上一篇, 我在 HttpModule 的Init方法中, 添加了自己的事件, 在Pipeline里, 就会把握注册的事件给执行了. 那么Pipeline是如何执行并且按照什么顺序执行的呢? 现在我们 ...
- [SOJ]Easy sort (归并排序)
Description You know sorting is very important. And this easy problem is: Given you an array with N ...
- equals和hashcode为什么要一起重写
equals()方法与hashCode()的通用协定是:2.1 如果两个对象相等(equal),那么必须拥有相同的哈希码(hash code)2.2 即使两个对象有相同的哈希值(hash code), ...
- ORM了解
1.hibernate通过读取Hibernate.cfg.xml文件创建SessionFactory,并通过SessionFactory创建Session(开始使用要打开,使用结束要关闭);通过Ses ...
- 我理解的session和cookie
tomcat管理session 理解tomcat是如何生成session的. 当用户请求到web资源有request.getSession()这段代码的时候,request首先会对请求的url判读是否 ...
- quagga源码分析--通用库command
quagga作为一个路由器软件,自然要提供人机接口. quagga提供snmp管理接口,而且,自然就会有对应的命令行管理格式,当然一般路由软件不会提供界面形式的,也许有webui,然而quagga并没 ...
- 获取Java的32位MD5实现
获取Java的32位MD5实现 public static String md5(String s) { char hexDigits[] = {'0','1','2','3','4','5','6' ...
- 一个在浏览器端将html 转为pdf 的js 插件 jsPDF
<!DOCTYPE html> <html> <head> <title>test</title> <meta http-equiv= ...
- 使用高通SDK开发AR应用
具体AR是什么效果我这里就不说了,直接上过程: 1.去官网注册一个帐号https://developer.vuforia.com 2.下载SDK for Unity,并导入Unity 3.点击Deve ...