Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接:
https://codeforces.com/contest/1265/problem/D
题意:
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?
思路:
考虑0只能和1,3只能和2,贪心的以01, 23去放,这样0必须小于等于1, 2和3同理,再往中间插21,如果剩下的2和1相差超过1就不能满足条件。
多一个可以插在开头或者结尾。还要考虑0和1为0,2和3为0的特殊情况。
好像暴力枚举也可以。。
代码:
#include<bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main()
{
cin >> a >> b >> c >> d;
if (((d != 0 || c != 0) && a > b) || ((a != 0 || b != 0) && d > c))
{
puts("NO\n");
return 0;
}
if (a == 0 && b == 0)
{
if (abs(d-c) > 1)
{
puts("NO\n");
return 0;
}
else
{
string res = "";
for (int i = 1;i <= min(c, d);i++)
res += "23";
if (c > d)
res += "2";
else if (c < d)
res = "3"+res;
cout << "YES" << endl;
for (int i = 0;i < res.length();i++)
cout << res[i] << ' ';
cout << endl;
return 0;
}
}
if (c == 0 && d == 0)
{
if (abs(a-b) > 1)
{
puts("NO\n");
return 0;
}
else
{
string res = "";
for (int i = 1;i <= min(a, b);i++)
res += "01";
if (a > b)
res += "0";
else if (a < b)
res = "1"+res;
cout << "YES" << endl;
for (int i = 0;i < res.length();i++)
cout << res[i] << ' ' ;
cout << endl;
return 0;
}
}
int l = b-a, r = c-d;
if (abs(l-r) > 1)
{
puts("NO\n");
return 0;
}
string res = "";
if (l-r == 1)
res += "1";
for (int i = 1;i <= a;i++)
res += "01";
for (int i = 1;i <= min(l, r);i++)
res += "21";
for (int i = 1;i <= d;i++)
res += "23";
if (r-l == 1)
res += "2";
cout << "YES" << endl;
for (int i = 0;i < res.length();i++)
cout << res[i] << ' ';
cout << endl;
return 0;
}
Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)的更多相关文章
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)
题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...
- Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries
题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...
随机推荐
- 使用Spring CROS解决项目中的跨域问题
CROS(Cross-Origin Resource Sharing) 用于解决浏览器中跨域请求的问题.简单的Get请求可以使用JSONP来解决,而对于其它复杂的请求则需要后端应用的支持CROS.Sp ...
- crontab 定时删除
/60 * * * /bin/find /usr/local/****/****/****/****/****.log.2019* -exec rm -f {} ; >/dev/null 2&g ...
- warning: LF will be replaced by CRLF in application.yml. The file will have its origina解决方法
环境: windows提交时报错如图所示: 原因是存在符号转义问题 windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示,解决办法: git con ...
- Spring Cloud Alibaba学习笔记(22) - Nacos配置管理
目前业界流行的统一配置管理中心组件有Spring Cloud Config.Spring Cloud Alibaba的Nacos及携程开源的Apollo,本文将介绍Nacos作为统一配置管理中心的使用 ...
- Unity的学习笔记(摇杆制作)
最近看到了一个很新颖的摇杆,就是按下后,会出现在按下的位置,并且拖着走的时候,到一定距离整个摇杆也会跟着走,于是自己测试做了一下这种摇杆 首先,先说一下我的摇杆预设体结构 代码挂在哪里都无所谓,关键是 ...
- Python之TensorFlow的基本介绍-1
一.TensorFlow™是一个基于数据流编程(dataflow programming)的符号数学系统,被广泛应用于各类机器学习(machine learning)算法的编程实现,其前身是谷歌的神经 ...
- 编译基于obs-studio的阿里巴巴直播工具tblive的过程和常见问题解决
tblive 简介 tblive开源项目对应的产品是千牛主播,是一个独立的PC端主播工具,基于开源软件OBS Studio来修改定制. 项目说明 tblive是一款优秀的基于obs-studio的直播 ...
- usercript and passwdcript array
usercript and passwdcript array ######################## # nsnet_usercript # xxd -g 4 -c 16 -s +$(( ...
- Install Gnome desktop
Install Gnome desktop http://www.dinggd.com/index.php/freebsd-8-0-rc1-gnome%E6%A1%8C%E9%9D%A2%E5%AE% ...
- 3.建造模式(Builder)
注:图片来源于 https://www.cnblogs.com/-saligia-/p/10216752.html 建造模式UML图解析: 代码: Director.h // // Created b ...