cf708B. Recover the String---(构造法)
题目链接: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---(构造法)的更多相关文章
- 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 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. 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, ...
- Recover the String
Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...
- 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 ...
- POJ 3295 Tautology (构造法)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7716 Accepted: 2935 Descrip ...
- Uva 120 - Stacks of Flapjacks(构造法)
UVA - 120 Stacks of Flapjacks Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &a ...
- 利用子集构造法实现NFA到DFA的转换
概述 NFA非有穷自动机,即当前状态识别某个转换条件后到达的后继状态不唯一,这种自动机不便机械实现,而DFA是确定有限状态的自动机,它的状态转换的条件是确定的,且状态数目往往少于NFA,所以DFA能够 ...
随机推荐
- BZOJ2883 : gss2加强版
首先离散化颜色 设pre[x]表示与x颜色相同的点上一次出现的位置,对于每种颜色开一个set维护 修改时需要修改x.x修改前的后继.x修改后的后继 询问[l,r]等价于询问[l,r]内pre[x]&l ...
- BZOJ1767 : [Ceoi2009]harbingers
设d[i]表示i到1的距离 f[i]=w[i]+min(f[j]+(d[i]-d[j])*v[i])=w[i]+d[i]*v[i]+min(-d[j]*v[i]+f[j]) 对这棵树进行点分治,每次递 ...
- C#创建桌面快捷方式 和 开机启动
/// <summary> /// 创建桌面快捷方式 2010-11-25 /// </summary> p ...
- TYVJ P1020 寻找质因数
做题记录:2016-08-08 描述 给出N个数字,试求质因数最大的数字. 输入格式 第一行,一个整数N,表示数字个数.接下来N行,每行一个整数A_i,表示给出的数字. 输出格式 一个整数,表示质因数 ...
- 十个JavaScript中易犯的小错误,你中了几枪?
序言 在今天,JavaScript已经成为了网页编辑的核心.尤其是过去的几年,互联网见证了在SPA开发.图形处理.交互等方面大量JS库的出现. 如果初次打交道,很多人会觉得js很简单.确实,对于很多有 ...
- Linux_屏蔽360、scanv、QQ管家等IP扫描
vi banip.sh #!/bin/bash echo "banip" iptables -A INPUT -s 221.204.203.0/24 -j DROP iptable ...
- 不要在init和dealloc函数中使用accessor
不要在init和dealloc函数中使用accessor 文章目录 Objective-C 2.0 增加了 dot syntax,用于简单地调用成员变量的 accessor.相当于 java 的 ge ...
- QTabWiget Change Color 改变颜色
Qt中的QTabWiget 类提供了一个标签控件,但是这个控件默认初始化的颜色是白色,和原窗口的颜色不同,看起来非常的违和,所以我们希望将其的背景颜色设为当前窗口的背景颜色.我们所要做的就是先将应用程 ...
- ITK 3.20.1 VS2010 Configuration 配置
Download ITK 3.20.1 Download VS2010 Download CMake 3.2.0 I assume you've already installed VS2010 an ...
- java中的this与super的区别
java中的this与super的区别 1. 子类的构造函数如果要引用super的话,必须把super放在函数的首位 代码如下: class Base { Base() { System.out.pr ...