日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Beautiful Sequence CodeForces - 1264B(暴力)

發(fā)布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Beautiful Sequence CodeForces - 1264B(暴力) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s1,s2,…,sn is beautiful if |si?si+1|=1 for all 1≤i≤n?1.

Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a+b+c+d numbers.

However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?

Input
The only input line contains four non-negative integers a, b, c and d (0<a+b+c+d≤105).

Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print “NO” (without quotes) in one line.

Otherwise, print “YES” (without quotes) in the first line. Then in the second line print a+b+c+d integers, separated by spaces — a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.

If there are multiple answers, you can print any of them.

Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.

It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
思路:分別考慮兩個數,三個數,四個數不為零的情況,然后if-else語句去寫就可以了。這是我目前為止寫的最長的if-else。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;int a,b,c,d;int main() {scanf("%d%d%d%d",&a,&b,&c,&d);if(a&&!b&&!c&&!d) {if(a==1) cout<<"YES"<<endl<<0<<endl;else cout<<"NO"<<endl;}else if(!a&&b&&!c&&!d){if(b==1) cout<<"YES"<<endl<<1<<endl;else cout<<"NO"<<endl;}else if(!a&&!b&&c&&!d){if(c==1) cout<<"YES"<<endl<<2<<endl;else cout<<"NO"<<endl;}else if(!a&&!b&&!c&&d){if(d==1) cout<<"YES"<<endl<<3<<endl;else cout<<"NO"<<endl;}else if(a&&b&&!c&&!d){if(abs(a-b)>1) cout<<"NO"<<endl;else {if(a>b){cout<<"YES"<<endl<<0<<" ";while(b--) cout<<"1 0 ";cout<<endl;}else if(b>a){cout<<"YES"<<endl<<1<<" ";while(a--) cout<<"0 1 ";cout<<endl;}else{cout<<"YES"<<endl;while(a--) cout<<"0 1 ";cout<<endl;}}}else if(a&&!b&&c&&!d) cout<<"NO"<<endl;else if(a&&!b&&!c&&d) cout<<"NO"<<endl;else if(!a&&b&&c&&!d){if(abs(b-c)>1) cout<<"NO"<<endl;else{if(b>c) {cout<<"YES"<<endl<<1<<" ";while(c--) cout<<"2 1 ";cout<<endl;}else if(c>b){cout<<"YES"<<endl<<2<<" ";while(b--) cout<<"1 2 ";cout<<endl;}else{cout<<"YES"<<endl;while(b--) cout<<"1 2 ";cout<<endl;}}}else if(!a&&b&&!c&&d) cout<<"NO"<<endl;else if(!a&&!b&&c&&d){if(abs(c-d)>1) cout<<"NO"<<endl;else{if(c>d){cout<<"YES"<<endl<<2<<" ";while(d--) cout<<"3 2 ";cout<<endl; }else if(d>c){cout<<"YES"<<endl<<3<<" ";while(c--) cout<<"2 3 ";cout<<endl;}else {cout<<"YES"<<endl;while(c--) cout<<"3 2 ";cout<<endl;}}}else if(a&&b&&c&&!d){if(abs(a+c-b)>1) cout<<"NO"<<endl;else{if(b>a+c){cout<<"YES"<<endl<<1<<" ";b--;while(b){if(a) cout<<"0 1 ",a--;else if(c)cout<<"2 1 ",c--;b--;}cout<<endl;}else if(b<a+c){cout<<"YES"<<endl<<0<<" ";a--;while(b){if(a) cout<<"1 0 ",a--;else if(c)cout<<"1 2 ",c--;b--;}cout<<endl;}else{cout<<"YES"<<endl;while(b){if(a) cout<<"0 1 ",a--;else if(c)cout<<"2 1 ",c--;b--;}cout<<endl;}}}else if(a&&b&&!c&&d) cout<<"NO"<<endl;else if(!a&&b&&c&&d){if(abs(b+d-c)>1) cout<<"NO"<<endl;else{if(c>b+d){cout<<"YES"<<endl<<2<<endl;c--;while(c){if(b) cout<<"1 2 ",b--;else if(d)cout<<"3 2 ",d--;c--;}cout<<endl;}else if(c<b+d){cout<<"YES"<<endl<<1<<endl;b--;while(c){if(b) cout<<"2 1 ",b--;else if(d)cout<<"2 3 ",d--;c--;}cout<<endl;}else{cout<<"YES"<<endl;while(c){if(b) cout<<"1 2 ",b--;else if(d)cout<<"3 2 ",d--;c--;}cout<<endl;}}}else {if(a>b||d>c||abs(b+d-a-c)>1) cout<<"NO"<<endl;else{vector<int> p;if(a+c>=b+d) {for(int i=0;i<a+c;i++){if(i<a) p.push_back(0);else p.push_back(2);}cout<<"YES"<<endl;for(int i=0;i<p.size();i++){cout<<p[i]<<" ";if(b) cout<<1<<" ",b--;else if(d) cout<<3<<" ",d--;}cout<<endl;}else {for(int i=0;i<b+d;i++){if(i<b) p.push_back(1);else p.push_back(3);}cout<<"YES"<<endl;for(int i=0;i<p.size();i++){cout<<p[i]<<" ";if(a) cout<<"0 ",a--;else if(c) cout<<"2 ",c--;}cout<<endl;}}}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Beautiful Sequence CodeForces - 1264B(暴力)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。