CodeForces 1265 D. Beautiful Sequence

Posted aaazhuo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 1265 D. Beautiful Sequence相关的知识,希望对你有一定的参考价值。

贪心

#include <iostream>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;

const int maxn=100010;
int ans[maxn];
int a[4];
void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>b)
    {
        if(a==b+1&&!c&&!d)
        {
            cout<<"YES"<<endl;
            for(int i=0;i<b;i++) cout<<"0 1 ";
            cout<<0<<endl;
            return ;
        }
        else
        {
            cout<<"NO"<<endl;
            return ;
        }
    }
    if(d>c)
    {
        if(d==c+1&&!a&&!b)
        {
            cout<<"YES"<<endl;
            for(int i=0;i<c;i++) cout<<"3 2 ";
            cout<<3<<endl;
            return ;
        }
        else
        {
            cout<<"NO"<<endl;
            return ;
        }
    }
    b-=a;
    c-=d;
    if(abs(b-c)>1)
    {
        cout<<"NO"<<endl;
        return ;
    }
    else
    {
        cout<<"YES"<<endl;
        if(b==c+1) cout<<"1 ";
        for(int i=0;i<a;i++) cout<<"0 1 ";
        for(int i=0;i<min(b,c);i++) cout<<"2 1 ";
        for(int i=0;i<d;i++) cout<<"2 3 ";
        if(1+b==c) cout<<"2 ";
    }
}
int main()
{
    solve();
    return 0;
}

  

以上是关于CodeForces 1265 D. Beautiful Sequence的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces - 1265D(贪心+暴力)

Codeforces Codeforces Round #484 (Div. 2) D. Shark

[codeforces 55]D. Beautiful numbers

CodeForces D. Concatenated Multiples

codeforces 987 D. Fair

codeforces 985 D. Sand Fortress