CodeForces 708B Recover the String
构造。
根据$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的更多相关文章
- codeforces 709D D. Recover the String(构造)
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...
- 【CodeForces】708 B. Recover the String 数学构造
[题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...
- Recover the String
Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...
- 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 ...
- 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 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- B. Recover the String
B. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【动态规划】【最短路】Codeforces 710E Generate a String
题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...
随机推荐
- Web API中使用Dependency Resolver
Web API中使用Dependency Resolver 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyo ...
- Asp.Net Web API 导航3
Asp.Net Web API 导航 Asp.Net Web API第一课:入门http://www.cnblogs.com/aehyok/p/3432158.html Asp.Net Web A ...
- Build FFmpeg for iOS
FFmpeg Build Instructions MAC 10.8 or better Copy ffmpeg-2.0.tar.bz2 (https://ffmpeg.org/releases/ff ...
- WinDBG调试.NET程序示例
WinDBG调试.NET程序示例 好不容易把环境打好了,一定要试试牛刀.我创建了一个极其简单的程序(如下).让我们期待会有好的结果吧,阿门! using System; using System.Co ...
- 对无返回值、使用Action或Func作为参数、多重载的方法进行单元测试
VS2012 Unit Test(Void, Action, Func) —— 对无返回值.使用Action或Func作为参数.多重载的方法进行单元测试 [提示] 1. 阅读文本前希望您具备如下知识: ...
- 移动收入超PC端 盛大文学战略转型初见成效
随着智能手机和平板电脑的普及,越来越多的互联网服务也开始向移动端拓展,除了传统的互联网服务如搜索.即时通信之外,网络文学这项新兴的互联网业务也没忽视对移动端的布局. 7月9日,中国最大的网络文学出版平 ...
- [基础]RHEL6下LINUX服务器批量部署
包准备:xinetd,tftp-server,dhcp,httpd,system-config-kickstart,syslinux,nfs 试验环境: 本机地址:192.168.46.98 ...
- Mysql监控及优化
一.Mysql连接数 1.配置Mysql连接数: vim /etc/my.cnf [mysqld]下面修改 max_connections=1000 不写默认为100. wait_timeout=60 ...
- CoreCRM 开发实录 —— 单元测试、测试驱动开发和在线服务
测试不是问题,问题是怎么测试. ## 单元测试 我认为单元测试已经是无可争议的最佳开发实践之一.但是很多人并不同意这个观点.他们的说法无非是:写测试需要花很多时间,需求又经常变动,一但变动,一大片测试 ...
- java类静态域、块,非静态域、块,构造函数的初始化顺序
原文:http://ini.iteye.com/blog/2007835 面试的时候,经常会遇到这样的考题:给你两个类的代码,它们之间是继承的关系,每个类里只有构造器方法和一些变量, 构造器里可能还有 ...