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(暴力)相关推荐

  1. 枚举 ---- B. Power Sequence[Codeforces Round #666 (Div. 2)][暴力]

    B. Power Sequence 有 n 个数,现在要求将这个数列变成一个等比数列的形式 你可以将这 n 个数随意排列 或者将任意一个数加一或者减一操作,每次此类操作都要花费 1,问最少花费是多少 ...

  2. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  3. CodeForces - 1265D Beautiful Sequence(贪心+构造+思维)

    题目链接:点击查看 题目大意:给出a个0,b个1,c个2,d个3,要求构造一种序列,使得数列两两之间绝对值之差等于1,若不能构造输出NO 题目分析:首先我们需要稍微讨论一下特殊情况,那就是对于两端的数 ...

  4. (CodeForces 548B 暴力) Mike and Fun

    http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...

  5. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个"VK"子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试 ...

  6. Long Beautiful Integer CodeForces - 1268A(贪心构造)

    You are given an integer x of n digits a1,a2,-,an, which make up its decimal notation in order from ...

  7. CodeForces 1138B暴力+剪枝

    [题目链接]Circus [题目分析]理解题意以后发现并没有什么思路,没有什么算法能用,这个时候就应该想到计算机解题的本质--暴力求解.相应的就要想到剪枝的条件,肯定不能盲目的暴力求解. 总共有四种人 ...

  8. codeforces 574B 暴力+复杂度分析

    题目: B. Bear and Three Musketeers time limit per test 2 seconds memory limit per test 256 megabytes i ...

  9. Codeforces 769B 暴力

    传送门:题目 题意: 一开始,只要第一个学生知道消息,第一个学生想把消息传给所有人,只能点对点传输,而且每个人只能发送有限条消息,求方案,如果没法达成,输出-1 题解: 如果第一个学生可传达消息数不为 ...

最新文章

  1. node express 学习笔记
  2. Python入门100题 | 第011题
  3. optee的启动过程
  4. .NET程序员应该理解的几种软件保护方法 辛苦开发的程序需要建立有效的保护机制...
  5. XGBoost原理及在Python中使用XGBoost
  6. linux-0.11内核 任务的堆栈切换
  7. [版本1.11.4已修复]简书安卓UI界面Bug:主界面消失
  8. 客服客户聊天系统源码分享
  9. 【开发】开源的网络攻防黑客游戏d0x3d
  10. 转载 禁止ie浏览器打开
  11. 简单实用 Firefox最有用的20大插件热力推荐
  12. 干货分享:RS485通信和Modbus通信协议汇总
  13. 5.8架构设计原则案例分析
  14. 【参赛作品12】基于华为云鲲鹏弹性云服务器部署openGauss数据库-实验
  15. Android 加密 AES
  16. 开发规范-java代码注释及IDEA配置代码注释模板
  17. C++核心准则​T.46:要求模板参数最少是正规或半正规的
  18. Android进阶七:RecyclerView拖动滑动之ItemTouchHelper
  19. vue vuex 模块化 namespace
  20. MIPS汇编语言指令类型

热门文章

  1. flask mysql项目模板渲染_Flask框架模板渲染操作简单示例
  2. 判断 小程序_第五届美亚杯赛前必备:从案情资料到小程序解题
  3. iphone闪退修复工具_iOS 13.3越yu工具再更新,修复若干问题(附自签教程)
  4. html 点击文本框则选中,JS事件 内容选中事件(onselect)选中事件,当文本框或者文本域中的文字被选中时,触发onselect事件,同时调用的程序就会被执行。...
  5. windows 10下载链接
  6. 服务器上的此文件夹中具有更多项目,清理或删除“可恢复的项目”文件夹中的项目...
  7. mysql中having的例子_mysqlgroupby/having/distinct查询使用例子_MySQL
  8. Jar mismatch! Fix your dependencies
  9. linux内核函数kmalloc,Linux_Linux平台上几个常见内核内存分配函数,* kmallocPrototype:#incl - phpStudy...
  10. DevNet网站上线