模拟

首先可以求出 0 和 1 的个数

之后按照01 10 的个数贪心安排

细节太多 错的都要哭了

#include<bits/stdc++.h>
using namespace std; int main(){
int a,b,c,d;
while(~scanf("%d %d %d %d",&a,&b,&c,&d)) {
int suc = 1; int t1,t2;
t1 = sqrt(2*a); t2 = sqrt(2*d);
t1 ++; t2 ++;
if(t1*(t1-1) != 2*a || t2*(t2-1) != 2*d) suc = 0; if(d == 0) {
if(!suc) printf("Impossible\n");
else if(b == 0 && c == 0) {
for(int i = 0; i < t1; ++i) printf("0"); printf("\n");
}else if(b+c == t1) {
if(t1 == 1) {
if(b) printf("01\n");
else printf("10\n");
continue;
}
int cc = 0;
if(cc == b) printf("1");
for(int i = 0; i < t1; ++i) {
printf("0");
cc ++;
if(cc == b) printf("1");
} printf("\n");
}
else printf("Impossible\n");
continue;
}else if(a == 0) {
if(!suc) printf("Impossible\n");
else if(b == 0 && c == 0) {
for(int i = 0; i < t2; ++i) printf("1"); printf("\n");
}else if(b+c == t2) {
int cc = 0;
if(cc == c) printf("0");
for(int i = 0; i < t2; ++i) {
printf("1"); cc ++;
if(cc == c) printf("0");
} printf("\n");
}
else printf("Impossible\n");
continue;
} if(b+c != t1*t2) suc = 0;
int num1 = 0, pos1 = 0;
num1 = c/t1; pos1 = c%t1;
int all = num1 + (pos1 > 0);
if(all > t2) suc = 0; if(suc) {
for(int i = 0; i < num1; ++i) printf("1");
int cc = t1;
for(int i = 0; i < t1; ++i) {
cc --;
printf("0");
if(cc == pos1 && cc != 0) printf("1");
}
for(int i = 0; i < t2-all; ++i) printf("1"); printf("\n");
}
else printf("Impossible\n");
}
return 0;
}

CF AIM Tech Round 3 (Div. 2) D - Recover the String的更多相关文章

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

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

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

  4. 【AIM Tech Round 4 (Div. 2) D Prob】

    ·题目:D. Interactive LowerBound ·英文题,述大意:       有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...

  5. AIM Tech Round 3 (Div. 2)

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

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

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

  7. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...

  8. AIM Tech Round 3 (Div. 2) A

    Description Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Ko ...

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

随机推荐

  1. Hadoop RPC简单例子

    jdk中已经提供了一个RPC框架-RMI,但是该PRC框架过于重量级并且可控之处比较少,所以Hadoop RPC实现了自定义的PRC框架. 同其他RPC框架一样,Hadoop RPC分为四个部分: ( ...

  2. 51NOD 1238 最小公倍数之和 V3 [杜教筛]

    1238 最小公倍数之和 V3 三种做法!!! 见学习笔记,这里只贴代码 #include <iostream> #include <cstdio> #include < ...

  3. POJ Building roads [二分答案 2SAT]

    睡觉啦 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...

  4. UVa 1378 A Funny Stone Game [博弈论 SG函数]

    A Funny Stone Game 题意: $n \le 23$堆石子,每次选择$i < j \le k$,从$i$拿走1颗$j,k$各放入一颗,不能取就失败.求先手是否必胜以及第一次取的策略 ...

  5. jQuery源码研究——怎么看源码

    废话 这几天有想看源码的想法,于是就开始了源码的研究,经过几天的摸索发现看源码还是有点技巧在里面的,想着把这些东东写下来作为一个小总结. 在一个多月前我对Vue源码进行了一次研究,那时看源码的方式基本 ...

  6. 简单的led驱动程序设计

    基于ok6410: led驱动程序: vim led.c #include<linux/kernel.h>#include<linux/module.h>#include< ...

  7. SparkSteaming运行流程分析以及CheckPoint操作

    本文主要通过源码来了解SparkStreaming程序从任务生成到任务完成整个执行流程以及中间伴随的checkpoint操作 注:下面源码只贴出跟分析内容有关的代码,其他省略 1 分析流程 应用程序入 ...

  8. cnblogs的使用

    cnblogs的使用 选择使用cnblogs而不是csdn,答案是很明显的.csdn每次创建博客之后会有一段时间的审核期,这大大的影响了用户体验.此外,cnblogs的用户群以及使用模式有着很大的诱惑 ...

  9. [记]WIndow/Linux 获取本机(全部)IPv4、IPv6、MAC地址方法 (C/C++)

    Linux 获取本机IP.MAC地址用法大全 //#include <sys/types.h> #include <ifaddrs.h> #include <sys/io ...

  10. 正则表达式的方法:replace,match,test(replace参数可以是回调函数)

    1.replace: 作用对象:字符串 功能:用于替换字符串中的某些字符 参数:(1)正则表达式 (2)要替换的字符串 或者 回调函数 var str="1 2 3 4 5 6 7 8 9& ...