链接:

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(构造)的更多相关文章

  1. 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 ...

  2. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  3. 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 ...

  4. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  5. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  6. Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

  7. Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)

    题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...

  8. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...

  9. Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries

    题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...

随机推荐

  1. python基础 — random库

    python中用于生成伪随机数的函数库是random 因为是标准库,使用时候只需要import random random库包含两类函数,常用的共8个 --基本随机函数: seed(), random ...

  2. 【LEETCODE】38、167题,Two Sum II - Input array is sorted

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  3. Markdown新手入门

    目录 Markdown新手入门 一.字体样式 二. 标题 三.列表 四.引用和代码块 五.插入图片和超链接 六.创建表格 七. 上标和下标 八.着重显示和高亮显示 我是尾巴 Markdown新手入门 ...

  4. vue中$router与$route的区别

    $.router是VueRouter的实例,相当于一个全局的路由器对象.包含很多属性和子对象,例如history对象 $.route表示当前正在跳转的路由对象.可以通过$.route获取到name,p ...

  5. Socket简单Demo

    Socket协议网上介绍的有很多了,就不在画蛇添足了,本文主要编写一个小Demo,介绍下它具体实现 一:Socket服务器端 package com.founderit; import java.io ...

  6. SpringCloud之Zuul网关简介、映射vs过滤配置使用

    目的: Zuul路由网关简介及基本使用 Zuul路由映射配置 Zuul请求过滤配置 Zuul路由网关简介及基本使用 Zuul简介: Zuul是从设备和网站到Netflix流应用程序后端的所有请求的前门 ...

  7. .NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态

    原文:.NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态 在 Windows 系统中,一段时间不操作键盘和鼠标,屏幕便会关闭,系统会进入睡眠状态.但有些程序(比如游戏.视频和演示文稿)在运行过程中应该 ...

  8. 你再也不用使用 Redux、Mobx、Flux 等状态管理了

    Unstated Next readme 的中文翻译 前言 这个库的作者希望使用 React 内置 API ,直接实现状态管理的功能.看完这个库的说明后,没有想到代码可以这个玩.短短几行代码,仅仅使用 ...

  9. JavaWeb开发回顾总结【不断更新中】

    1.Java语言编程 2.Servlet & JSP(JavaServer Pages) JSPGet方法中文乱码,以上是我的一篇解决Get方法的文章. 关于编码的约定,从项目的一开始就要规定 ...

  10. Jenkins配置Publish Over SSH讲解说明

    原创 Jenkins配置Publish Over SSH讲解说明 2018-08-22 11:59:30 M.Blog 阅读数 3764更多 分类专栏: Jenkins   版权声明:本文为博主原创文 ...