题意:有一个01组成的串,告知所有长度为2的子序列中,即00,01,10,11,的个数a,b,c,d。输出一种可能的串。

先求串中0,1的数目x,y。

首先,如果00的个数a不是0的话,设串中有x个0,C(X,2)=a,那么x*(x+1)=2a,解方程(其实只要看sqrt(x)*(sqrt(x)+1)等不等于2a),x没有整数解就IMPOSSIBLE。同理得出1的个数y。如果00个数是0看01个数。

第二,如果x*y!=b+c则IMPOSSIBLE,具体自己举个例子就明白。

最后,先将所有的0组成一个串str,再从右边开始逐个加1。具体来说,在str最右加1个1,01数量增加x个,倒二位置加,增加x-1个......总共要b个01,先往最右增加b/x个1。然后还缺b1个01,在倒二位置加b1/(x-1)个......循环结束。

乱码。。。。。。

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon a00,a01,a10,a11;
cin>>a00>>a01>>a10>>a11;
bool ok1=,ok2=;
lon sq1=sqrt(a00*),sq2=sqrt(a11*);
if(sq1*(sq1+)==*a00)ok1=;
if(sq2*(sq2+)==*a11)ok2=;
lon num0=sq1+,num1=sq2+;
if(a00==&&a01==&&a10==)num0=;
if(a11==&&a01==&&a10==)num1=;
if(num0==num1&&num0==)cout<<<<endl;
else if(ok1&&ok2)
{
if(a01+a10!=num0*num1)cout<<"Impossible"<<endl;
else if(num0==)
{
cout<<string(num1,'')<<endl;
}
else if(num1==)
{
cout<<string(num0,'')<<endl;
}
else
{
string str(num0,'');
lon right1num=a01/num0;
lon rem=num1-right1num;
str+=string(right1num,'');
lon stillneed01=a01-num0*(a01/num0);
for(int i=(int)str.size()-right1num-,j=;i>=;--i,++j)
{
lon cur0=num0-j;
if(cur0==)
{
str=string(rem,'')+str;
break;
}
int right1num=stillneed01/cur0;
str.insert(str.begin()+i,right1num,'');
stillneed01-=cur0*right1num;
rem-=right1num;
}
cout<<str<<endl;
}
}
else cout<<"Impossible"<<endl;
return ;
}

codeforces708b// Recover the String //AIM Tech Round 3 (Div. 1)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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}$ 挺简单的构造, 注意到可以通 ...

  6. CF AIM Tech Round 3 (Div. 2) D - Recover the String

    模拟 首先可以求出 0 和 1 的个数 之后按照01 10 的个数贪心安排 细节太多 错的都要哭了 #include<bits/stdc++.h> using namespace std; ...

  7. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  8. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  9. AIM Tech Round 4 (Div. 2)ABCD

    A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. python使用pip下载模块

    举例下载串口模块pyserial: 下载安装了python之后,打开cmd,在python的安装目录里,搜索pip,把pip3.7.exe拖进cmd,然后输入pip3.7.exe install py ...

  2. P4363 [九省联考2018]一双木棋chess

    思路 容易发现只能在轮廓线的拐点处落子,所以棋盘的状态可以用一个n+m长度的二进制数表示 转移就是10变成01 代码 #include <cstdio> #include <algo ...

  3. 案例2:用一条SQL查询出数学语文成绩都大于80分的学生姓名?

    方法1: 查出科目成绩有小于80分的学生姓名,再约束并去重学生不等于查出来的姓名 select distinct A.name from t_score A where A.name not in(s ...

  4. BSEG和BSIS、BSAS、BSID、BSAD、BSIK、BSAK 六个表的关系

    BSEG和BSIS.BSAS.BSID.BSAD.BSIK.BSAK六个表的关系 1.数据关系: BSAS+BSIS+BSAK+BSIK+BSAD+BSID = BSEG 2.六个表说明: clear ...

  5. _itemmod_creation_enchant

    该表控制物品产生时自动获得随机附魔效果 comment  备注  entry  物品entry  slot  附魔位置1-5,这些位置都可以用来产生自带附魔效果  groupId  附魔组Id 对就_ ...

  6. 转 这种方法可以免去自己计算大文件md5 的麻烦

    using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEditor;using ...

  7. Docker个人理解总结

    最新在学习Docker,记录下自己对Docker的理解. 一.Docker是什么? 1. Docker是一个能够把开发的应用程序自动部署到容器的开源引擎. 2.Docker使用Google公司推出的G ...

  8. Python 3种运行方式

    Python 命令行 >>>print('Hello World!') 小程序 在hello.py中写入如下,并保存: print('Hello World!') $python h ...

  9. N的阶乘(10000) 51 nod——1057 (大数)

    像这些大整数加法或者乘法什么的思想都一样,就是截位存取,累积进位,最后逆序输出就可以啦 PS:小生是用10000来存取的,300MS就能A,如果单个存取有点危险,题目时间限制好像是1000ms,大家可 ...

  10. 文件编码检测.ZC

    1.今天(20181101) 发现 g文件中的 xml头 和 文件编码不一致,最后发现 貌似是我搞错了,人家的文件 编码方式写的是对的. 我发现的现象是:XML里面写的是"GBK" ...