*Codeforces Round #235 (Div. 2) C. Team(贪心)

时间:2022-09-29
本文章向大家介绍*Codeforces Round #235 (Div. 2) C. Team(贪心),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

https://codeforces.com/contest/401/problem/C

题目大意:
给定n个0,m个1;

让我们构建出一个字符串满足:不能连续2个以上的0,不能出现3个连续的1;

可以的话就输出任意正确的结果,不能的话就输出“-1”。
inputCopy
1 2
outputCopy
101

inputCopy
4 8
outputCopy
110110110101

inputCopy
4 10
outputCopy
11011011011011

inputCopy
1 5
outputCopy
-1

这模拟题自己写了大半天都没有写出来,我服了,智商退化,还得是佬儿的指导下

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const int MAXN=2000020;
const int N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0);ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        //以0为基准,不要以1为基准
        if(m<n-1||m>2*(n+1)) cout<<"-1"<<endl;
        else
        {
            while(n>0)//1跟0搭配使用
            {
                //在每一步的开始提前删除一个0,
                LL minn=min((LL)2,m-(n-1));//1的每次输出个数最多为两个

                //cout<<endl<<m-(n-1)<<" minn "<<minn<<endl;
                for(int i=0;i<minn;i++)//输出1的个数
                {
                    cout<<"1";
                    m--;
                }
                cout<<"0";//顺带一个0
                n--;
            }
            while(m>0)//多余的1在末尾输出
            {
                cout<<"1";
                m--;
            }
            cout<<endl;
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Vivian-0918/p/16743055.html