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能够 ...
随机推荐
- SSH框架优缺点
SSH框架优缺点 开源是3个框架共有的优点 Struts2框架(MVC框架)的优点如下: 1) 实现了MVC模式,层次结构清晰,使程序员只需关注业务逻辑的实现: 2) 丰富的标签库,大大提高了开发 ...
- Jquery焦点图实例
对于很多建站的朋友来讲,焦点图并不陌生,一般的企业站,门户站都会用到焦点图.我们平时在写html代码的时候,很多人为了省时省力,对于焦点图都是在网上下载一些人家写好的代码,直接套上去即可,很多时候我自 ...
- java 面向对象--------时间作业
编写Java应用程序.首先,定义一个时钟类——Clock,它包括三个int型 成员变量分别表示时.分.秒,一个构造方法用于对三个成员变量(时.分.秒) 进行初始化,还有一个成员方法show()用于显示 ...
- ArcEngine 不能再打开其他表了
在IFeatureClass.Search()是弹出这个问题,根据网上的资料,采用 System.Runtime.InteropServices.Marshal.ReleaseComObject()或 ...
- PHP显示日期、周几、农历初几、什么节日函数编程代码
<?function rili($style,$Atime){ $debug = false; $glmonth = date("n",$Atime); //1-12 ...
- 前端编码规范(4)—— CSS 和 Sass (SCSS) 规范
CSS and Sass (SCSS) style rules ID and class naming ID和class(类)名总是使用可以反应元素目的和用途的名称,或其他通用名称.代替表象和晦涩难懂 ...
- 让apache不区分图片和文件后缀大小写
加载mod_speling模块: LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so 开启模块: CheckSpelli ...
- discuz全局数组变量 后台各项设置 完整版
$_G 保存了 Discuz! 中所有的预处理数据 缓存能够很好的提高程序的性能,一些配置数据没必要每次都查询数据库,只要在修改了的时候更新下缓存即可. Discuz! 中所有的缓存保存在 $_G[c ...
- UAPStudio授权过期的解决方法,重新授权
1.启动lisence服务器,生成硬件锁, 并导入授权. 需要注意的地方:1.点击工具栏“帮助”下的“UAP-STUDIO”授权管理. 2.删除“D:\UAP-STUDIO\Platform\bin” ...
- HDU 3555 数位dp入门
开始想用dp[i][j]来记录第i位j开头含有49的数的个数 但是init后并不知道如何进行cal 想了想可以用不要62的思想 当作不要49来做 然后减一下 就好 看网上的代码 不要62和这道题用的d ...