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 string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x, y}.
In these problem you are given four integers a00, a01, a10, a11 and have to find any non-empty string s that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than 1 000 000.
Input
The only line of the input contains four non-negative integers a00, a01, a10 and a11. Each of them doesn't exceed 109.
Output
If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed 1 000 000.
Sample Input
1 2 3 4
Sample Output
Impossible
Hint
题意
你要构造一个只含有01的串,其中子序列:00有a个,01有b个,10有c个,11都d个。
如果不能,输出impossible
题解:
通过00和11,我们知道这个串里面0和1分别有多少个,然后我们就可以构造了。
假设0全部放在前面,1全部放在后面,那么如果把一个1扔到最前面,那么C就会减去当前0的个数。
然后我们就通过这个玩意儿去构造就好了。
代码
#include<bits/stdc++.h>
using namespace std;
long long f(long long x)
{
return x*(x-1)/2;
}
long long a,b,c,d,A,B;
int flag=0;
int main()
{
cin>>a>>b>>c>>d;
for(long long i=0;f(i)<=a;i++)
{
if(f(i)==a)
{
for(long long j=0;f(j)<=d;j++)
{
if(f(j)==d)
{
if(i*j==b+c)
{
A=i;
B=j;
flag=1;
}
}
}
}
}
if(flag==0)
return puts("Impossible"),0;
if(A==0&&B==0)
return puts("Impossible"),0;
int sum = A+B;
for(int i=0;i<sum;i++)
{
if(c>=A)
{
B--;
c-=A;
printf("1");
}
else
{
A--;
printf("0");
}
}
printf("\n");
return 0;
}
AIM Tech Round 3 (Div. 1) B. Recover the String 构造的更多相关文章
- 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 ...
- CF AIM Tech Round 3 (Div. 2) D - Recover the String
模拟 首先可以求出 0 和 1 的个数 之后按照01 10 的个数贪心安排 细节太多 错的都要哭了 #include<bits/stdc++.h> using namespace std; ...
- codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...
- AIM Tech Round 3 (Div. 1) (构造,树形dp,费用流,概率dp)
B. Recover the String 大意: 求构造01字符串使得子序列00,01,10,11的个数恰好为$a_{00},a_{01},a_{10},a_{11}$ 挺简单的构造, 注意到可以通 ...
- 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 ...
- AIM Tech Round 3 (Div. 2)
#include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...
- AIM Tech Round 3 (Div. 2) A B C D
虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...
- AIM Tech Round 3 (Div. 2) B
Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...
随机推荐
- html template--(来自网易)
html template 概述 包含完整头部信息和主体结构的HTML基础模板. 代码展示 <!DOCTYPE html> <html> <head> < ...
- 利用 ASP.NET 的内置功能抵御 Web 攻击 (1)
摘要: Dino 总结了最常见的 Web 攻击类型,并介绍了 Web 开发人员可以如何使用 ASP.NET 的内置功能来改进安全性. 一.ASP.NET 开发人员应当始终坚持的做法 如果您正在阅读本文 ...
- Jquery 较好的效果
仿google图片效果图片展示相册(jquery)的演示页面 产品相册展示插件slideshow多图可翻页 懒人建站 Jquery分享A Jquery分享B Jquery分享C Jquery分享D
- R9—R常用函数分类汇总
数据结构 一.数据管理 vector:向量 numeric:数值型向量 logical:逻辑型向量 character:字符型向量 list:列表 data.frame:数据框 c:连接为向量或列表 ...
- oracle 学习day01
1.关系型数据库的设计范式 范式:是关系型数据库关系模型规范化的标准.范式是建立在函数依赖的基础上. 函数依赖:如果表中某一个字段Y的值是有另外一个字段或一组字段X的值来确定,就称作Y函数 ...
- Linux中普通用户提权为超级用户
首先创建一个普通用户,并且给普通用户设置一个密码,保证能用su 命令能用普通用户登录 [root@ahu ~]# useradd test [root@ahu ~]# passwd test New ...
- 【干货】操纵时间 感受威胁 MAC time时间戳视角
来源:Unit 4: Unix/Linux Forensics Analysis 4.1 Unix/Linux Forensics Analysis MAC Times Sleuthkit工具的MAC ...
- Linux入侵问题排查
1.深入分析,查找入侵原因 1.1 检查隐藏账户及弱口令 1.1.1.检查服务器系统及应用账户是否存在弱口令 检查说明:检查管理员账户.数据库账户.MySQL账户.tomcat账户.网站后台管理员账户 ...
- BAT脚本加防火墙455端口
@echo off mode con: cols=85 lines=30 :NSFOCUSXA title WannaCry勒索病毒安全加固工具 color 0A cls echo. echo. ec ...
- malloc 函数详解
很多学过C的人对malloc都不是很了解,知道使用malloc要加头文件,知道malloc是分配一块连续的内存,知道和free函数是一起用的.但是但是: 一部分人还是将:malloc当作系统所提供的或 ...