cf708B. Recover the String---(构造法)

时间:2023-01-23 13:54:47

题目链接: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&period; Recover the String&lpar;构造&rpar;

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

  3. AIM Tech Round 3 &lpar;Div&period; 1&rpar; B&period; Recover the String 构造

    B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each str ...

  4. 【CodeForces】708 B&period; 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 &lpar;Div&period; 2&rpar;D&period; Recover the String(贪心&plus;字符串)

    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. nodejs之异步思想

    nodejs的精髓就是"异步",但什么是异步呢?我们来看一个例子: var start =new Date; setTimeout(function(){ var end =new ...

  2. php 微信3 自定义菜单

    <pre name="code" class="php"><pre name="code" class="htm ...

  3. ant 关键字和关键语句

    学习ant推荐的两个blog http://www.cnblogs.com/huozhicheng/archive/2010/04/08/2533199.htmlhttp://www.cnblogs. ...

  4. &lbrack;数&rsqb;昨天欠下的一道立体几何题HDU-4741

    并没有做到这道题,后来听学长说了题意,总之就是立体几何嗯 看了好几份题解,是的我知道是异面线段的距离了,可是看码完全不明orz. 这时候出现了一份清晰易懂甚至给出了公式来源的blog╰(*°▽°*)╯ ...

  5. Windows Server 2016-系统安装软硬件要求

    本章为大家补充介绍安装 Windows Server 2016的最低系统要求. 如果安装时选择通过"服务器核心"选项进行安装,则应注意,没有安装任何 GUI 组件,并且将不能使用服 ...

  6. JIT和AOT编译详解

    JIT和AOT编译介绍 JIT - Just-In-Time             实时编译,即时编译 通常所说的JIT的优势是Profile-Based Optimization,也就是边跑边优化 ...

  7. Hive学习之路 (十八)Hive的Shell操作

    一.Hive的命令行 1.Hive支持的一些命令 Command Description quit Use quit or exit to leave the interactive shell. s ...

  8. python概念-其实只要简单了解一下&comma;但是却讲了将近两个小时的知识点&colon;元类

    说实话,我真心不太想总结这个东西,算了,炒一下egon的吧 1 引子 1 class Foo: 2 pass 3 4 f1=Foo() #f1是通过Foo类实例化的对象 python中一切皆是对象,类 ...

  9. poi 取excel单元格内容时,需要判断单元格的类型,才能正确取出

    以下内容非原创,原文链接http://blog.sina.com.cn/s/blog_4b5bc01101015iuq.html ate String getCellValue(HSSFCell ce ...

  10. 如何使一个div能够铺满整个页面? &amp&semi;&amp&semi; 模态框的制作 &amp&semi;&amp&semi; outerHTML

    说明: 使用 ele.outerHTML = '' 这样的方法可以很容易的清除一个元素. 当然也可以使用parent.removeChild() ,但是相较而言,还是使用 outerHTML = '' ...