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:
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
input
Copy
1 2
output
Copy
101
input
Copy
4 8
output
Copy
110110110101
input
Copy
4 10
output
Copy
11011011011011
input
Copy
1 5
output
Copy
-1 题意:给一组只有0和1的数组,排序满足条件:
1.两个相邻的零不能在一起
2.三个1不能在一起
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
- // ctrl+shift+C 注释
- //ctrl+shift+x 取消
- #define int long long
- #define YES cout<<"YES"<
- #define NO cout<<"NO"<
- #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- typedef long long ll;
- typedef pair<int,int> PII;
- const int N=2e5+10;
- const ll M=1e18+10;
- const int mod=1e9+7;
- int a[N],sum[N];
- priority_queue<int,vector<int>,greater<int> >pq;
- set<int>se;
- map<int,int>mp;
- queue<int>qu;
- vector<int>v;
- deque<int>de;
- int n,m;
- void solve()
- {
- cin>>n>>m;
- if(m>n*2+2||n>m+1)
- {
- cout<<-1<
- return;
- }
- int f=0;
- if(m==n)// 010101
- {
- for(int i=0;i
- {
- cout<<"10";
- }
- }
- else if(m-n<=2&&m>n)// n=2 m=3 10101
- {
- for(int i=1;i<=n;i++)
- {
- cout<<"10";
- }
- for(int i=1;i<=m-n;i++)
- cout<<"1";
- }
- else if(n-1==m)// n=3 m=2 01010
- {
- for(int i=1;i<=m;i++)
- {
- cout<<"01";
- }
- cout<<0;
- }
- else if(m
2)// 0多 n=4 m=7 11011011010 - {
- int res=n*2-m;
- for(int i=1;i<=n-res;i++)
- {
- cout<<"110";
- }
- for(int i=1;i<=res;i++)
- {
- cout<<"10";
- }
- }
- else if(m==n*2)
- {
- for(int i=0;i
- {
- cout<<"110";
- }
- }
- else if(m>n*2&&m<=n*2+2)//1多 n=4 m=9 1101101101101
- {
- for(int i=0;i
- {
- cout<<"110";
- }
- int res=m-n*2;
- for(int i=1;i<=res;i++)
- {
- cout<<1;
- }
- }
- cout<
- }
- signed main()
- {
- int t=1;
- //cin>>t;
- while(t--)
- {
- solve();
- }
- }
-
相关阅读:
[Python]Django项目运行中系统用户为非root用户,需要去执行sudo命令并且不用输入密码(提升权限)
Elasticsearch 开放 inference API 增加了对 OpenAI chat completions 的支持
leetcode_171Excel表列序号
代码随想录Day18 LeetCode235 二叉搜索树的公共祖先 T701二叉搜索树中的插入操作 T140 删除二叉搜索树中的公共节点
齿轮故障诊断的实验数据集及python处理
Swift ——协议
对话ACE第四期:分布式数据库未来发展的挑战和机遇
63 x的平方根
linux取证——基础取证命令集合
mlops产品调研方案
-
原文地址:https://blog.csdn.net/qq_62079079/article/details/127562101