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\) ...
随机推荐
- Callable+Future
Future提供了三种功能: 1)判断任务是否完成: 2)能够中断任务: 3)能够获取任务执行结果 package com.moreas; import java.util.concurrent.Ca ...
- IDEA的一个设置, 关系到maven的运行, 默认是使用jre的, 有时候不够用需要改成jdk
- day29——socket套接字(少量不全)
day29 socket套接字 socket是处于应用层与传输层之间的抽象层,他是一组操作起来非常简单的接口(接受数据)此接口接受数据之后,交由操作系统. 为什么存在socket抽象层? 如果直接与操 ...
- hdu1016 Prime Ring Problem【素数环问题(经典dfs)】
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- SAS学习笔记57 template的管理
template查询 首先点击SAS Windows左上方查询框,输入“odst”或者“odstemplates”,如下所示: 然后点击enter键,进入查询的template文件夹,如下所示: 这里 ...
- Oracle scott解锁 以及连接数据库
最近公司需要使用oracle数据库,本地安装oracle进行测试,需要连接到数据库,但是发现scott账号 is locked; 原因:默认Oracle10g的scott不能登陆. 解决:(1)con ...
- DHCP服务器的架设
DHCP服务器的架设 一.DHCP服务器的安装要求: 搭建DHCP服务器需要一些必备条件支持,主要有以下方面: 需要一台运行Windows Server系统的服务器,并为其指定静态IP地址. 根据子网 ...
- ORM 查询练习
目录 ORM 查询练习 表结构 练习题 测试数据 准备 参考答案 ORM 查询练习 表结构 # 书 class Book(models.Model): title = models.CharField ...
- org.apache.commons.beanutils.ConversionException: No value specified解决办法
转自:https://www.cnblogs.com/linjiqin/archive/2011/07/21/2112628.html 当用到了java.sql.Date时间等非内置对象时,如果对象为 ...
- RabbitMQ topic 交换器
topic交换器:"."将路由键分为几个标识符,"*"匹配一个, "#"可以匹配多个 1:路由键为*或者#的时候 *:只能匹配单个的字符串 ...