模拟

首先可以求出 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. Laravel (5.5.33) 加载过程(一)

    说明:  由于公司项目使用Laravel 框架  也是第一次接触此框架  作为一个新手 记录使用过程的一些事情  以及对于框架源码分析的记录  整理自己的思路 也希望对大家有帮助  如果那里不对的地方 ...

  2. Animation Physics and The Realization Of Animation In Browsers

    Animation Physics Background With the development of computer science technology, people are facing ...

  3. js处理json js递归

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  4. IOS开发之记录用户登陆状态,ios开发用户登陆

    IOS开发之记录用户登陆状态,ios开发用户登陆 上一篇博客中提到了用CoreData来进行数据的持久化,CoreData的配置和使用步骤还是挺复杂的.但熟悉CoreData的使用流程后,CoreDa ...

  5. Java并发系列[6]----Semaphore源码分析

    Semaphore(信号量)是JUC包中比较常用到的一个类,它是AQS共享模式的一个应用,可以允许多个线程同时对共享资源进行操作,并且可以有效的控制并发数,利用它可以很好的实现流量控制.Semapho ...

  6. python实现三级菜单

    一.要求: 1.一开始打印出所有省份和提示 2.用户输入省份以此查询城市 3.在按照输出的城市名提示用户输入,最后输出用户所查询的区县名 4.随时输入"back"可以返回上一级菜单 ...

  7. FZU 2234

    题目为中文,题意略. 这个题目我开始用贪心做bfs两次,这样做是错的,因为两次局部的最优解并不能得出全局的最优解,以下面样例说明: 3 0   10   -1 10   10   10 1   0  ...

  8. java url demo

    // File Name : URLDemo.java import java.net.*; import java.io.*; public class URLDemo { public stati ...

  9. POJ - 1417 并查集+背包

    思路:很简单的种类并查集,利用并查集可以将所有的人分成几个集合,每个集合又分为好人和坏人集合,直接进行背包dp判断有多少种方法可以在取了所有集合并且人数正好凑足p1个好人的方案.dp(i, j)表示前 ...

  10. HDU - 1430 魔板 (bfs预处理 + 康托)

    对于该题可以直接预处理初始状态[0, 1, 2, 3, 4, 5, 6, 7]所有可以到达的状态,保存到达的路径,直接打印答案即可. 关于此处的状态转换:假设有初始状态为2,3,4,5,0,6,7,1 ...