codeforces708BRecover the String+数学构造
来源:互联网 发布:sql删除表数据 编辑:程序博客网 时间:2024/06/07 08:09
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.
Examples
Input
1 2 3 4
Output
Impossible
Input
1 2 2 1
Output
0110
让你还原一个01串,使得任意选2个,为“11”的个数有x11个,为“10”的个数有x10个,为“01”的个数有x01个,为“00”的个数有x00个。。。
首先可以由x11算出原串中1的个数,由x00算出原串中0的个数,那么n1*n0==x01+x01,等等一些列的条件判断出imposssible.注意0 0 0 0 的时候也成立为0,同理可以想到如果x00==0那么n0不一定就是0,也可以是1,所以直接判断x01和x10是否为0就可以判断出n0的个数。
之后知道n0,n1后,再来想构造。假设i位要填数字,它的后边要填m个1,那么我们想后边的x01的个数,如果x01
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<iostream>using namespace std;#define LL long longint getnumber(int x){ if(x==0) return 0; int p=sqrt(2*x); while(p*(p+1)<2*x) p++; if(2*x==p*(p+1)) return p+1; else return -1;}int main(){ int x00,x01,x10,x11; //cout<<getnumber(4950); scanf("%d %d %d %d",&x00,&x01,&x10,&x11); int number0=getnumber(x00); int number1=getnumber(x11); if(x00==0&&x01==0&&x10==0&&x11==0){ printf("0\n"); return 0; } if(number0==0&&(x01!=0||x10!=0)) number0++; if(number1==0&&(x01!=0||x10!=0)) number1++; if(number0==-1||number1==-1||number0*number1!=x10+x01||number0+number1==0){ printf("Impossible\n"); return 0; } int n=number0+number1; for(int i=0;i<n;i++){ if(x01>=number1){ printf("0"); x01-=number1; number0--; } else{ printf("1"); x10-=number0; number1--; } } printf("\n"); return 0;}/*0 0 0 01 2 0 06 0 0 00 0 0 6*/
- codeforces708BRecover the String+数学构造
- codeforces 709 D Recover the String (构造)
- 构造(Recover the String,cf 709D)
- cf 709D Recover the String(构造题)
- codeforces 709D Recover the String (构造+模拟)
- string------构造
- [CodeForces365C]Matrix[构造][数学]
- The String |
- The String ||
- AIM Tech Round 3 (Div. 2) -- D. Recover the String (思路题目--构造字符串)
- AIM Tech Round 3 (Div. 2) -- D. Recover the String (构造字符串)
- AIM Tech Round 3 (Div. 2) D. Recover the String 构造、贪心、多坑、WA162
- AIM Tech Round 3 (Div. 2) D. Recover the String (构造)
- AIM Tech Round 3 (Div. 1) B. Recover the String(构造)
- AIM Tech Round 3 (Div. 1) B. Recover the String 构造
- [数学-构造矩阵]NEFU 1113
- CF 709D 数学,构造
- hdu 5646 Partition数学+构造
- Unity UI(五):交互式控件之Button
- 二叉搜索树转换为双向链表
- 指针基础概念
- Java反射应用
- JS中的其他跨域技术
- codeforces708BRecover the String+数学构造
- Cookie的应用:显示用户上次浏览过的商品
- linux驱动开发经验逐步积累2
- Java异常处理和设计
- XML解析常用的技术
- Spark性能优化第十季之全球独家揭秘Spark统一内存管理
- CSS中行高的继承和单位之间的关系
- NVIDIA Jetson TK1学习与开发——JETPACK自动刷机
- JavaBean、EL表达式${ }、作用域-自动转换、常用方法