题目链接:http://codeforces.com/problemset/problem/708/B

意思是给出四个参数 
a00表01串中00对的数量 
a01表01串中01对的数量 
a10表01串中10对的数量 
a11表01串中11对的数量

求出一个符合条件的01串,如果不存在输出Impossible;

根据a00和a11可以求出0和1的个数;把cnt1个1放在前面,cnt0个0放在后面,此时的01串为0,当把0往前移动一位是01的个数会增加一,所以可以根据a01的个数移动0的位置;

当然在当a00为0时0的个数可能是0个也可能是1个要看a01和 a10同样1的个数也是一样;有对应的串时应满足1的个数*0的个数 = a01+a10的;

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
typedef long long LL;
#define INF 0x3f3f3f3f
#define N 1000100 using namespace std; int a[];
char ans[N]; int main()
{
for(int i=; i<; i++)
scanf("%d", &a[i]); if(!a[] && !a[] && !a[] && !a[])
{
printf("0\n");
return ;
} int cnt0, cnt1; if(!a[] && !a[] && !a[]) cnt0 = ;
else cnt0 = ; if(!a[] &&!a[] && !a[]) cnt1 = ;
else cnt1 = ; if(a[]) cnt0 = (int)sqrt(a[]*) + ;
if(a[]) cnt1 = (int)sqrt(a[]*) + ; if(a[]* != cnt0*(cnt0-) || a[]* != cnt1*(cnt1-) || cnt0*cnt1 != a[]+a[])
{
puts("Impossible");
return ;
} int p = , r = ; while(a[])
{
if(a[] >= cnt1)
{
ans[p++] = '';
a[] -= cnt1;
r++;
}
else
{
int m = cnt1-a[];
while(m) ans[p++] = '', m--;
ans[p++] = '', r++;
a[] = ;
}
} int s = p-r;
while(cnt1-s) ans[p++] = '', s++;
while(cnt0-r) ans[p++] = '', r++; puts(ans); return ;
}

cf708B. Recover the String---(构造法)的更多相关文章

  1. CF708B Recover the String 构造

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

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

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

  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. Recover the String

    Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...

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

  7. POJ 3295 Tautology (构造法)

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7716   Accepted: 2935 Descrip ...

  8. Uva 120 - Stacks of Flapjacks(构造法)

    UVA - 120  Stacks of Flapjacks Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld &a ...

  9. 利用子集构造法实现NFA到DFA的转换

    概述 NFA非有穷自动机,即当前状态识别某个转换条件后到达的后继状态不唯一,这种自动机不便机械实现,而DFA是确定有限状态的自动机,它的状态转换的条件是确定的,且状态数目往往少于NFA,所以DFA能够 ...

随机推荐

  1. HDU 4681 String(DP)

    题目链接 枚举A和B中每一段含有C的段,A的前面 后面和B前面后面,求最长公共子序.观察发现,可以预处理最长公共子序. #include <iostream> #include <c ...

  2. Java_获取当前月最后一天

    List<String> ms = DateUtils.getMonths(7,"yyyyMM"); SimpleDateFormat sdf = new Simple ...

  3. Centos下设置静态IP

    使用VirtualBox装了很多虚拟机,默认采用的DHCP的方式,但是随着虚拟机越来越多以后,这种方式很不方便,所以需要将机器的IP都设置为静态IP 需要添加的几项内容的解释:IPADDR    IP ...

  4. 理解with(nolock)(转载)

    本文导读:要 提升SQL的查询效能,一般来说大家会以建立索引(index)为第一考虑.其实除了index的建立之外,当我们在下SQL Command时,在语法中加一段WITH (NOLOCK)可以改善 ...

  5. NSString 处理技巧:分割字符串

    摘要 string类型是objective-c中用的最多的类型之一,有时会出现字符串中有我们不想要的字符. 如 "hello world"中的空格,或是"hello/wo ...

  6. [转] - QThread应用探讨

    QThread 似乎是很难的一个东西,特别是信号和槽,有非常多的人(尽管使用者本人往往不知道)在用不恰当(甚至错误)的方式在使用 QThread,随便用google一搜,就能搜出大量结果出来.无怪乎Q ...

  7. java执行时的两个常见问题(无法加载主类)

    问题1:javac不是内部或者外部命令 问题2:找不到或无法加载主类*** 这两个问题都和jdk的配置有关,一个是path一个是classpath.path:去哪里找编译或运行等工具(必须设置),cl ...

  8. jq实现多banner效果图

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...

  9. mac mysql环境配置

    安装mysql:http://www.mysql.com/downloads/ 找到 MySQL Community Edition (GPL) Community (GPL) Downloads » ...

  10. VS2012网布网站与IIS配置

    一 VS发布 1首先是 点击自己创建的 web项目 ,右键发布 2  在之后出现的界面中选择配置文件 , 选择或导入发布配置文件,下拉框,选择新建 跳转到下一步 3 在连接界面中 在发布方法中选择文件 ...