codeforces401C
Team
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that:
- there wouldn't be a pair of any side-adjacent cards with zeroes in a row;
- there wouldn't be a group of three consecutive cards containing numbers one.
Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
Input
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
Output
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
Examples
1 2
101
4 8
110110110101
4 10
11011011011011
1 5
-1 sol:这还是挺好构造的吧(虽然我挂的很惨惨惨惨惨惨惨)
如果1比0的两倍还多3个或者0比1多2个就GG了,否则就一定能构造出来
如果1比0多就先用110,再用10
如果0比1多就一直用010101,最后来个0
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
int n,m; //n个0,m个1
int main()
{
R(n); R(m);
if(m-n*>) return *puts("-1");
if(n-m>) return *puts("-1");
if(m>=n)
{
while(m>n&&n)
{
putchar(''); putchar(''); putchar('');
m-=; n--;
}
if(n==)
{
while(m--) putchar('');
}
else
{
while(m--)
{
putchar(''); putchar('');
}
}
}
else
{
while(m--)
{
putchar(''); putchar('');
}
putchar('');
}
return ;
}
/*
input
1 2
output
101 input
4 8
output
110110110101 input
4 10
output
11011011011011 input
1 5
output
-1
*/
codeforces401C的更多相关文章
随机推荐
- Visual Studio 2012 与此版本的 Windows 不兼容。有关详细信息,请联系 Microsoft
参考网址:Visual Studio 2012 与此版本的 Windows 不兼容 解决 下载更新包安装:http://www.microsoft.com/zh-CN/download/details ...
- Maven的porfile与SpringBoot的profile结合使用详解
使用maven的profile功能,我们可以实现多环境配置文件的动态切换,可参考我的上一篇博客.但随着SpringBoot项目越来越火,越来越多人喜欢用SpringBoot的profile功能 ...
- ASP.NET Core 2.1 源码学习之 Options[1]:Configure
配置的本质就是字符串的键值对,但是对于面向对象语言来说,能使用强类型的配置是何等的爽哉! 目录 ASP.NET Core 配置系统 强类型的 Options Configure 方法 Configur ...
- [翻译] 使用 .NET Core 3.0 创建一个 Windows 服务
原文: .NET Core Workers as Windows Services 在 .NET Core 3.0 中,我们引入了一种名为 Worker Service 的新型应用程序模板.此模板旨在 ...
- git 的 cat-file 的命令用法
命令选项 git cat-file 的命令显示版本库对象的内容.类型.及大小信息. -t Instead of the content, show the object type identifie ...
- Python中for循环搭配else的陷阱
假设有如下代码: for i in range(10): if i == 5: print 'found it! i = %s' % i else: print 'not found it ...' ...
- 会议室预订系统(meeting room booking system)
一.mrbs mrbs:(meeting room booking system) 二.效果 三.models from django.db import models # Create your ...
- 软件工程(FZU2015) 赛季得分榜,第七回合
SE_FZU目录:1 2 3 4 5 6 7 8 9 10 11 12 13 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分=团队得分+个人贡献分 个人贡献分: 个人 ...
- js处理ajax返回的json数组
一.json对象和json数组的区别 jsonObject = {} # json对象 jsonArray=[{},{}] # json数组 二.数据处理 前台接收到后台传过来的json数组实际上是一 ...
- Bridge (br0) Network on Linux
动手实践虚拟网络 - 每天5分钟玩转 OpenStack(10) - CloudMan - 博客园https://www.cnblogs.com/CloudMan6/p/5296573.html li ...