构造。

根据$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. mark_May

    嗯神忙的五月总算是过完了. 草草的做完研究性学习,浑浑噩噩的考了数学联赛,以及在考试的上一周还在疯狂的看未闻花名,貌似还有前几个星期不懂是吃错药还是怎样 总急着把2013的题目刷完=-=可是貌似到现在 ...

  2. ASP.NET虚拟路径小结

    一.虚拟路径的概念 “虚拟路径”是指请求 URL 中跟在服务器标识符后面的部分举例. 如绝对路径:http://www.mysite.com/MyApp/Default.aspx,其对应的虚拟路径为: ...

  3. Bootstrap3.0学习第八轮

    Bootstrap3.0学习第八轮(工具Class)   前言 阅读之前您也可以到Bootstrap3.0入门学习系列导航中进行查看http://www.cnblogs.com/aehyok/p/34 ...

  4. SharePoint RBS 安装(集成Office Web Apps)

    前言 本文完全原创,转载请说明出处,希望对大家有用. 本篇博客是个人总结,一方面以便日后查看,另一方面希望能为其他人提供一些便利. 阅读目录 安装RBS 为多个内容数据库开启RBS 正文 目的:在Sh ...

  5. Hadoop Streaming框架学习2

    Hadoop Streaming框架学习(二) 1.常用Streaming命令介绍 使用下面的命令运行Streaming MapReduce程序: 1: $HADOOP_HOME/bin/hadoop ...

  6. BST&AVL&红黑树简单介绍

    (BST&AVL&红黑树简单介绍) 前言: 节主要是给出BST,AVL和红黑树的C++代码,方便自己以后的查阅,其代码依旧是data structures and algorithm ...

  7. Google photos -- reverse thinking

    As a hacker, do the hacking. Here I mean the [hacker](http://en.wikipedia.org/wiki/Hacker_(term) ) . ...

  8. C语言之分支结构 if(一)

    一 程序的三种基本结构 顺序结构:程序从上往下依次执行,这个叫顺序结构 分支结构:有选择的执行或者不执行某段代码 循环结构:重复的执行某段代码 二 分支结构之if 最简单的俩种用法 (tips: if ...

  9. (十一)if...else&for循环&while循环

    ----------------------------------if else------------------------------1.最基本的if语句:if name =="Al ...

  10. linux 安装 Chrome

    一.添加PPA 从Google Linux Repository(http://www.google.com/linuxrepositories/)下载安装Key,或把下面的代码复制进终端,回车,需要 ...