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\) ...
随机推荐
- JMeter进行Apache Kafka负载测试
1.卡夫卡负载测试 在这个Apache Kafka教程中,我们将了解如何使用Apache JMeter,如何在Apache Kafka上执行Kafka负载测试.此外,这个Kafka负载测试教程教我们如 ...
- laravel使用辅助函数url()引入js和css静态文件
使用laravel框架时可以将静态文件如,js文件,css文件,放到resources文件夹下的js下,当然也可以放到public文件夹下的js文件夹下,publi文件夹下默认情况下是没有css,js ...
- idea单行注释优化成不在行首注释
- docker-compose 单机容器编排
docker-compose用来在单机上编排容器(定义和运行多个容器,使容器能互通) docker-compose将所管理的容器分为3层结构:project service container d ...
- VsCode中好用的git源代码管理插件GitLens
1.在插件tab搜索GitLens 2.安装成功后将光标移至代码行即会显示代码编写者 3.在VsCode左侧菜单栏,点击GitLens图标即可查看History,也可以查看全部的日志 4.查看上下pu ...
- IdentityServer4实现OAuth2.0四种模式之客户端模式
一,准备内容 IdentityServer4 是Asp.net core的一个中间件,用于添加符合OpenId Connect和OAuth2.0规范的终端到Asp.net Core应用.在这里简单介绍 ...
- 进入恢复模式(Recovery HD)
进入恢复模式(Recovery HD) 1,选中要启动的虚拟机,随后点击VM菜单的启动按钮后面向下箭头,随后点击菜单项”打开电源时进入固件“. 2,在虚拟机里面,用上下键移动到”Enter setup ...
- PHP敏感信息脱敏函数
测试 $name = '王刚'; $mobile = '13817558198'; $name = desensitize($name,1,1); $mobile = desensitize($mob ...
- Flutter Image(图片)
Image是一个用于展示图片的组件.支持 JPEG.PNG.GIF.Animated GIF.WebP.Animated WebP.BMP 和 WBMP 等格式. Image 有许多的静态函数: ne ...
- SIM7500 SIM7600 SIM800 HTTP
解释 //Start HTTP service AT+HTTPINIT //Stop HTTP service AT+HTTPTERM //Set HTTP Parameters value /* & ...