【题目链接】:http://codeforces.com/problemset/problem/709/D

【题意】



给你一个序列;

给出01子列和10子列和00子列以及11子列的个数;

然后让你输出一个符合要求的序列;

【题解】



这里

00和11可以确定出序列中0和1的个数;

但有边缘数据

00如果为0代表什么?

->没有0或者是有1个0

11如果为0代表什么?

->没有1或者是有1个1

对这两种情况需要特判一下(两种情况的特判需要用到01和10的数量)

看代码吧。

然后这两种情况排除之后;

00和11就都大于0了;

则可以根据

00=a0*(a0-1)/2

11=a1*(a1-1)/2

来求出0的个数和1的个数;

具体的;

你需要对2*00开根号->x

同时你还有算一下

(x+1)*x/2是不是等于00

因为如果不是的话就表示没有符合要求的0的个数的序列满足要求;

那种情况也要输出无解;

1同理;

然后我们算出1的个数和0的个数;

把所有的1都放在最前面,然后0的放在后面;

这样a10等于0的个数乘1的个数;

然后可以验证你每把最右边那个1往右交换一个0,a10会减1,a01会加1;

则按照这个规则;

每次看看a10和输入的a10的差为多少rest

while(rest>=num0){

**把最右边那个1和最右边那个0交换;

**rest-num;

}

然后rest可能还有剩余

则把最右边那个1和这个1往右数rest个0交换位置;

就能再减去rest个10了;

根据上述规则可知;

如果输入的a10+a01!=1的个数*0的个数

则输出无解;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; int a00, a01, a10, a11;
string s; void work(int num0, int num1){
s = " ";
rep1(i, 1, num1) s += '1';
rep1(i, 1, num0) s += '0';
if (a01 + a10 != num0*num1) puts("Impossible"),exit(0);
int ta10 = num1*num0;
int j = num1,i = 0;
LL rest = ta10 - a10;
while (rest>=num0)
{
swap(s[j], s[num1 + num0 - i]);
j--; i++;
rest -= num0;
}
swap(s[j], s[j + rest]);
s.erase(0, 1);
cout << s << endl;
exit(0);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(a00), rei(a01), rei(a10), rei(a11);
if (a00 == 0){
//no zero
if (a01 == 0 && a10 == 0){
int len = sqrt(2 * a11)+1;
if (len*(len - 1) == 2 * a11)
{
rep1(i, 1, len) printf("1");
return 0;
}
} //one zero
if (a11 == 0){
//no one
if (a10 == 0 && a01 == 0) return puts("0"), 0; //one one
if (a10 + a01 == 1){
if (a10 == 1) return puts("10"), 0;
if (a01 == 1) return puts("01"), 0;
}
}
else
if (a11 > 0) {
int len = sqrt(2 * a11) + 1;
if (len*(len-1)==2*a11)
work(1, int(sqrt(2 * a11) + 1));
}
puts("Impossible");
return 0;
}
if (a11 == 0)
{
//no one
if (a10 ==0 && a01 == 0) {
int len = sqrt(2 * a00) + 1;
if (len*(len - 1) == 2 * a00) {
rep1(i, 1, len) printf("0");
return 0;
}
} //one one
assert(a00 > 0);
int len = sqrt(2 * a00) + 1;
if (len*(len - 1) == 2 * a00)
work(int(sqrt(2 * a00) + 1), 1);
puts("Impossible");
return 0;
}
int len = sqrt(2 * a00) + 1, len1 = sqrt(2 * a11) + 1;
if (len*(len-1)==2*a00 && len1*(len1-1)==2*a11)
work(int(sqrt(2 * a00) + 1), int(sqrt(2 * a11) + 1));
puts("Impossible");
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 709D】Recover the String的更多相关文章

  1. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. 【Codeforces 1132F】Clear the String

    Codeforces 1132 F 题意:给一个串\(S\),问每次删除连续的一段相同字母,最少删几次将原串删空. 思路:考虑区间\(dp\),我们看要删多少次能把\([l,r]\)删空,那么最终答案 ...

  3. 【CodeForces 624C】Graph and String

    题 题意 n个表示abc三个字符的点,所有a和b是相连的,所有b和c是相连的,所有相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【HDOJ 1009】 CRB and String

    [HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...

  6. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

  7. 【codeforces 779D】String Game

    [题目链接]:http://codeforces.com/contest/779/problem/D [题意] 给你一段操作序列; 按顺序依次删掉字符串1中相应位置的字符; 问你最多能按顺序删掉多少个 ...

  8. 【codeforces 801B】Valued Keys

    [题目链接]:http://codeforces.com/contest/801/problem/B [题意] 定义一个对两个字符串x,y的f(x,y)函数; 返回的是一个字符串; 这个返回的字符串的 ...

  9. 【codeforces 801A】Vicious Keyboard

    [题目链接]:http://codeforces.com/contest/801/problem/A [题意] 一个字符串只由VK组成; 让你修改一个字符; 使得剩下的字符串里面子串VK的个数最大; ...

随机推荐

  1. springboot开发过程中的小坑(持续更新)

    1. 启动的Application必须放到一个package下面,如下: package com.example.kikidemo; import org.springframework.boot.S ...

  2. js工作备注

    { field : 'state', title : '事件状态', align: 'center', width : 120, formatter : function(value, row, in ...

  3. spring cloud config搭建说明例子(三)-添加actuator

    添加心跳 服务端 ConfigServer pom.xml添加actuator包 <dependency> <groupId>org.springframework.cloud ...

  4. jQuery——表单应用(2)

    多行文本框应用之高度变化 HTML: <!--表单-多行文本框应用-高度变化--> <!DOCTYPE html> <html> <head> < ...

  5. httpd 安装ssl证书

    1) 安装ssl模块 # yum install mod_ssl -y Ps:安装完成后,会在/etc/httpd/conf.d/下生成一个ssl.conf配置文件. 2) 先建一个目录用来放ssl证 ...

  6. 有关lower_bound()函数的使用

    lower_bound()函数需要加载头文件#include<algorithm>,其基本用途是查找有序区间中第一个大于或等于某给定值的元素的位置,其中排序规则可以通过二元关系来表示. 函 ...

  7. 题解报告:hdu 1698 Just a Hook(线段树区间修改+lazy懒标记的运用)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  8. jQuery中$this和$(this)的区别

    要写一个点击弹窗任意地方,关闭弹窗.点击事件写标签在元素上 onclick =  closepop(this),这时候很容易搞不清楚怎么去获取当前元素 function closepop(e){ va ...

  9. Windows10环境中 laravel任务调度 如何启动调度

    Windows10环境中 laravel任务调度 如何启动调度 一:问题由来 1:今天在做用laravel开发订单系统的时候,需要使用定时任务来大批量提交订单,测试一下订单金额是否有误.发现larav ...

  10. CSS 如何让li横向居中显示

    先给一个简单的示例HTML代码 <body> <form id="form1" runat="server"> <div id=& ...