Problem - D - Codeforces

题意 : 有 a 个0,b个1,c个2,d个3,构成一个序列,使得每两个数字之间的差值为1

题解: 就是以四种数字分别为起点,暴力模拟

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=4e5+50;
const ll inf=1e18;
const ll mod=998244353;
ll a[N];
pll q[N];
ll vis[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll sum=0;
for(ll i=1;i<=4;i++){ cin>>a[i];sum+=a[i];}
for(ll i=1;i<=4;i++){
if(!a[i]) continue;
vector<ll> temp(5,0);
vector<ll> pt;
for(ll j=1;j<=4;j++) temp[j]=a[j];
ll now=i;
while(1){
pt.push_back(now);
temp[now]--;
if(now>=2&&temp[now-1]) now--;
else if(now<=3&&temp[now+1]) now++;
else break;
}
if(pt.size()!=sum) continue;
if(temp[1]+temp[2]+temp[3]+temp[4]==0){
cout<<"YES"<<endl;
for(ll j=0;j<pt.size();j++) cout<<pt[j]-1<<" ";
cout<<endl;
return 0;
}
}
cout<<"NO";
}

Codeforces Round #604 (Div. 2) -D的更多相关文章

  1. Codeforces Round #604(Div. 2,

    // https://codeforces.com/contest/1265/problem/D /* 感觉像是遍历的思维构造题 有思路就很好做的 可以把该题想象成过山车或者山峰...... */ # ...

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

  3. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

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

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

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

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

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

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

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

  8. Codeforces Round #604 (Div. 2) 部分题解

    链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...

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

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

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

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

随机推荐

  1. javaweb_Http学习

    1. 什么是HTTP? HTTP(超文本传输协议)是一个简单的请求-响应协议,它通常运行在TCP之上. 文本:html,字符串,~... 超文本:图片,音乐,视频,定位,地图..... 默认端口:80 ...

  2. 我熬夜开发了一款简约实用、支持多平台的Markdown在线编辑器(开源)

    前言 之前,一直想开发一款属于自己的Markdown编辑器,主要是自己平常写文章可以更加灵活操作,另外扩宽自己的视野也是非常不错的选择啊!所以在周末就决定玩耍一番.首先我调研了很多线上热门的md编辑器 ...

  3. jdbc连接数据库问题

    ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Fail ...

  4. Servlet 体系结构

    Servlet体系结构 Servlet -- 接口 Genericservlet -- 抽象类 继承类接口 实现了空方法  只需要复写service方法 HttpServlet -- 抽象类  对Ht ...

  5. 用Python做了个图片识别系统(附源码)

    本项目将使用python3去识别图片是否为色情图片,会使用到PIL这个图像处理库,并且编写算法来划分图像的皮肤区域 介绍一下PIL: PIL(Python Image Library)是一种免费的图像 ...

  6. dolphinscheduler简单任务定义及复杂的跨节点传参

    dolphinscheduler简单任务定义及跨节点传参 转载请注明出处 https://www.cnblogs.com/funnyzpc/p/16395094.html 写在前面 dolphinsc ...

  7. JTable和MVC设计模式

    JTable: 用JTable类可以以表格的形式显示和编辑数据 . JTable类的对象并不存储数据,它只是数据的表现 data MVC ~数据,表现和控制三者分离,各负其责 ~M=Model(模型) ...

  8. Java 17 中的模式匹配与和类型

    Java 17 中的模式匹配与和类型 从 Spring Security 获取用户谈起 使用 Spring Security做用户校验和权限控制时,常常使用和线程绑定的容器来获取当前登录用户. // ...

  9. 类型转换_str()函数与int()函数

    数据类型转换 需要将不同数据类型拼接在一起的时候就需要先进行数据类型转换 str+str//这里的+叫做连接字符,有点类似C++中的操作符重载,老对象里面的内容了 在python中整型和字符串类型不能 ...

  10. ToString()格式化输出

    C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...