codeforces 708B (数学构造)
来源:互联网 发布:新闻网页源码 编辑:程序博客网 时间:2024/06/05 14:48
For each string s consisting of characters '0' and '1' one can define four integersa00, 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.
The only line of the input contains four non-negative integers a00, a01, a10 and a11. Each of them doesn't exceed 109.
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.
1 2 3 4
Impossible
1 2 2 1
0110
题意:已知 a,b,c,d. 构造不大于1e6的字符串,使得其中子序列 00 ,01,10,11 的数量 = a,b,c,d。
已知,知道 00 11,的数目 可以知道 0,1的数量 x*(x-1) =a 快速求得正整数解得方法是 开方+1,然后相乘验证一下是否有解。
关于 01和10的数量,假设把0全放左边,1全放右边,得出01的数目就是 cnt1*cnt2 每次把1左移一位,10数量增加,01数量减少
#include <bits/stdc++.h>using namespace std;int num[1000010];int main(){int a,b,c,d;cin>>a>>b>>c>>d;int cnt1=sqrt(2*a)+1;int cnt2=sqrt(2*d)+1;if(cnt1*(cnt1-1)!=2*a||cnt2*(cnt2-1)!=2*d){puts("Impossible");return 0;}memset(num,0,sizeof(num));if(a+b+c+d==0){puts("0");return 0;}if(a+b+c==0){for(int i=1;i<=cnt2;i++)printf("1");return 0;}if(a&&b+c+d==0){for(int i=1;i<=cnt1;i++)printf("0");return 0;}if(cnt1*cnt2!=b+c){puts("Impossible");return 0;}int h=0;while(c){if(c>=cnt1){c-=cnt1;num[++h]=1;}else{++h;num[h+cnt1-c]=1;c=0;break;}}for(int i=1;i<=cnt2-h;i++)num[cnt1+cnt2+1-i]=1;for(int i=1;i<=cnt1+cnt2;i++)printf("%d",num[i] );puts("");}
- codeforces 708B (数学构造)
- codeforces 603B (数学)
- Codeforces 605B 构造
- Codeforces 639B (构造)
- CodeForces 359B 构造
- CodeForces 66D 数学构造
- CodeForces-707c[数学构造]
- CodeForces - 611B 数学思维
- Codeforces #164 B. Buttons (数学
- Codeforces 174B【模拟构造】
- 【Codeforces 141 B Hopscotch 】+ 构造
- 【Codeforces 746B Decoding】 + 构造
- Codeforces 891B Gluttony 构造
- codeforces 549B B. Looksery Party(构造)
- codeforces 359B B. Permutation(简单构造)
- Codeforces 509D. Restoring Numbers 构造+数学
- codeforces 24 Game(数学构造)
- 【CodeForces 534A】Exam 【数学构造】
- 要提高SQL查询效率where语句条件的先后次序应如何写
- 大数据WEB阶段(十一)Ajax、URL编码
- Dollar Dayz
- Php-打印所有错误
- Zk笔记(一):Zookeeper的两种安装和配置(Windows):单机模式与集群模式
- codeforces 708B (数学构造)
- Qt 模型视图编程
- ActiveMQ消息队列的使用学习笔记
- WebService知识汇总
- android开发环境的配置
- 位 字节 字 字长
- 算法复杂度
- Spring Boot多数据源配置与使用
- 谈谈JAVA的代理模式认识 一——为什么使用代理模式