构造。

根据$a[0][0]$可以求得$0$的个数$p$,根据$a[1][1]$可以求得$1$的个数$q$。 如果找不到$p$或$q$,那么就无解。

每一个$0$放到序列中的任何一个位置,假设和前面的$1$产生了$x$对$10$,和后面的$1$产生了$y$对$01$,那么$x+y$一定等于$q$。

也就是说如果$p*q$不等于$a[0][1]+a[1][0]$,那么就无解了。否则只要将$1$一个一个放进序列中,凑成$1$前面的$0$的个数总和是$a[0][1]$就可以了。

上面的方法对一般的情况都是成立的,对于三种特殊情况需要特判一下:$[1].$$0$ $0$ $0$ $0$   $[2].$$0$ $0$ $0$ $X$   $[3].$$X$ $0$ $0$ $0$。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} LL p=-,q=-,a[][];
int pos[]; int main()
{
for(int i=;i<;i++) for(int j=;j<;j++) scanf("%lld",&a[i][j]); for(LL i=;i*(i-)<=*a[][];i++)
{ if(i*(i-)==*a[][]) { p=i; break;} } for(LL i=;i*(i-)<=*a[][];i++)
{ if(i*(i-)==*a[][]) { q=i; break;} } if(p==-||q==-) { printf("Impossible\n"); return ; } if(a[][]==&&a[][]==&&a[][]==&&a[][]==)
{ printf("0\n"); return ; } if(a[][]==&&a[][]==&&a[][]==&&a[][]!=)
{for(int i=;i<=q;i++) printf(""); printf("\n"); return ;} if(a[][]!=&&a[][]==&&a[][]==&&a[][]==)
{ for(int i=;i<=p;i++) printf(""); printf("\n"); return ; } if(p==-||q==-) printf("Impossible\n");
else if(p+q>) printf("Impossible\n");
else if(p*q!=a[][]+a[][]) printf("Impossible\n");
else
{
for(int i=;i<=p;i++)
{
if(q>=a[][]) pos[a[][]]++,a[][]=;
else pos[q]++,a[][]=a[][]-q;
}
for(int i=;i<=pos[];i++)printf("");
for(int i=;i<=q;i++)
{
printf("");
for(int j=;j<=pos[i];j++) printf("");
}
printf("\n");
}
return ;
}

CodeForces 708B 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】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  3. Recover the String

    Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...

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

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

  6. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  7. B. Recover the String

    B. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

随机推荐

  1. jQuery的奥秘

    颜海镜 高效jQuery的奥秘 讨论jQuery和javascript性能的文章并不罕见.然而,本文我计划总结一些速度方面的技巧和我本人的一些建议,来提升你的jQuery和javascript代码.好 ...

  2. LigerUI+MVC的应用1

    [项目开发]LigerUI+MVC的应用(一) 近期因为稍微空闲有点时间,就晚上回家自己在随便写写代码,也就边写边记,中间主要采用了微软的MVC4.0框架.虽然目前公司也是使用的MVC的模式,但是因为 ...

  3. MongoDB:锁机制

    --1 MongoDB 使用的锁 MongoDB 使用的是“readers-writer”锁, 可以支持并发但有很大的局限性,当一个读锁存在,许多读操作可以使用这把锁,然而, 当一个写锁的存在,一个单 ...

  4. Excel报表开发(主要讲Excel的导入和导出)

    一.Excel数据导入 连接字符串Excel2003版: OleDbConnection conn = new OleDbConnection("provider=Microsoft.Jet ...

  5. [转]UIWebView的Javascript运行时对象

    An alternative, that may get you rejected from the app store, is to use WebScriptObject. These APIs ...

  6. js 冒泡 捕获

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> ...

  7. 关于Grunt可视化的尝试

    关于Grunt可视化的尝试 使用Grunt遇到的问题? 必须要安装NodeJS 必须安装grunt-cli 需要编写复杂的Gruntfile.js规则 每个项目中必须存在nodejs的grunt模块 ...

  8. 简单的mvc之三:灵活的路由(上)

    在上一篇关于管线的随笔中已经提及了管线,通过对管线的分析,我们可以得到下面几个结论:路由系统由URLRoutingModule模块实现,它订阅了PostResolvRequestCache事件:路由系 ...

  9. YSlow的性能测试提示

    Add an Expires or a Cache-Control Header tag: server There are two aspects to this rule: For static ...

  10. Make Things Move -- Javascript html5版(一)文件目录结构和工具方法准备

    从这一篇开始,就来开始我们的make things move之旅吧 在此之前,要知道ActionScript(AS)的语法和JS是不一样的,AS是相对于JS而言更好的支持了面向对象的特性,所以我们可以 ...