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的更多相关文章

  1. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

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

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

  4. 【CodeForces】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  5. B. Recover the String

    B. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...

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

  7. CF708B Recover the String 构造

    For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 an ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. CodeForces 708B Recover the String

    构造. 根据$a[0][0]$可以求得$0$的个数$p$,根据$a[1][1]$可以求得$1$的个数$q$. 如果找不到$p$或$q$,那么就无解. 每一个$0$放到序列中的任何一个位置,假设和前面的 ...

随机推荐

  1. NHibernate联合主键详细示例

    使用NHibernate实现一对多,多对一的关联很是简单,可如果要用复合主键实现确实让人有些淡淡的疼.虽然很淡疼但还是要去抹平这个坑,在下不才,愿意尝试. 以示例进入正文,源码下载地址: 一.数据表关 ...

  2. SQL注入(三)

    邮给我一个密码 我们意识到虽然不能添加一条新的记录在members表中,但我们可以通过修改一个存在的记录, 这也获得了我们的证明是可行的. 从先前的步骤中,我们知道bob@example.com在系统 ...

  3. java 实现Excel压缩成Zip导出

    1 概述 在web项目中常见的一种场景就是将文件导出为Excel,但是当需要导出多个Excel时,使用者将频繁操作,这样就严重降低了项目的友好交互性以及易用性,那么怎么才能优雅的解决这个问题呢?笔者今 ...

  4. CodeForces 213B Numbers

    $dp$,组合数. $dp[i][j]$表示只用数字$i$,$i+1$,$i+2$......,$9$,凑成长度为$j$的并且数字$i$到$9$符合要求的方案数.只要枚举数字$i$用几个就可以转移了. ...

  5. 三分钟跑起jsblocks

      1下载代码 git clone https://github.com/astoilkov/jsblocks-seed.git 2安装依赖 Peng@PENG-PC /F/home/qianduan ...

  6. WPS Office 二次开发简易教程。

    http://bbs.wps.cn/forum.php?mod=viewthread&tid=22004642

  7. Hex Workshop(16进制编辑利器) 6.7.2绿色版

    软件名称: Hex Workshop 6.7.2绿色版(16进制编辑利器) 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 1.8MB 图片预览: 软件简介 ...

  8. 【IE6的疯狂之九】li在IE中底部空行的BUG

    曾经写过[IE6的疯狂之六]li在IE中底部3像素的BUG(增加浮动解决问题),原文地址:http://www.css88.com/archives/421: IE6 BUG大全: http://ww ...

  9. linux 安装php的redis拓展

    安装步骤: #wget  https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz #tar -zxvf 2.2.4 #cd phpredi ...

  10. [DP之计数DP]

    其实说实在 我在写这篇博客的时候 才刚刚草了一道这样类型的题 之前几乎没有接触过 接触过也是平时比赛的 没有系统的做过 可以说0基础 我所理解的计数dp就是想办法去达到它要的目的 而且一定要非常劲非常 ...