zoukankan      html  css  js  c++  java
  • codeforces401C

    Team

     CodeForces - 401C 

    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

    Input
    1 2
    Output
    101
    Input
    4 8
    Output
    110110110101
    Input
    4 10
    Output
    11011011011011
    Input
    1 5
    Output
    -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=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0');    return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    int n,m; //n个0,m个1 
    int main()
    {
        R(n); R(m);
        if(m-n*2>2) return 0*puts("-1");
        if(n-m>1) return 0*puts("-1");
        if(m>=n)
        {
            while(m>n&&n)
            {
                putchar('1'); putchar('1'); putchar('0');
                m-=2; n--;
            }
            if(n==0)
            {
                while(m--) putchar('1');
            }
            else
            {
                while(m--)
                {
                    putchar('1'); putchar('0');
                }
            }
        }
        else
        {
            while(m--)
            {
                putchar('0'); putchar('1');
            }
            putchar('0');
        }
        return 0;
    }
    /*
    input
    1 2
    output
    101
    
    input
    4 8
    output
    110110110101
    
    input
    4 10
    output
    11011011011011
    
    input
    1 5
    output
    -1
    */
    View Code
     
  • 相关阅读:
    [skill][c][ld][gcc] 明确指定gcc在链接时明确使用静态库
    [administrative][lvm] lvm 分区修改
    [administrative] windows 下制作USB启动盘的工具
    [administrative][archlinux][netctl][wpa_supplicant] 查看WIFI链接信息
    [skill][makefile] makefile 常用内容记录
    [security] security engine things
    [administrative][CentOS] 新装系统时如何正确精准的选择基础环境和软件包
    [filesystem][archlinux][disk encryption][btrfs] btrfs
    [cipher][archlinux][disk encryption][btrfs] 磁盘分区加密 + btrfs
    [administrative][archlinux][clonezilla][disk cloning] 一块 windows 10 硬盘的备份
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10651251.html
Copyright © 2011-2022 走看看