CodeForces - 1265D(贪心+暴力)
题意
https://vjudge.net/problem/CodeForces-1265D
a个0,b个1,c个2,d个3,问是否存在一种排列方案使得任意相邻两数之差==1
思路
分类讨论太麻烦了,直接暴力搞!
枚举0123每个数作为第一个数,然后优先看这个数-1还有没有,有的话就放进去,没有就看这个数+1,如果两个都没有了,那就break,最后判断0123的数量是否都为0即可。
为什么要先放x-1?这是一种贪心的思路,放了x+1的话那么x-1在后面可能就放不了了,所以优先放x-1。
代码
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll p[N],q[N];
vector<int> ans;
int main()
{
std::ios::sync_with_stdio(false);
cin>>p[0]>>p[1]>>p[2]>>p[3];
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
q[j]=p[j];
int x=i;
if(!q[x]) continue;
ans.clear();
q[x]--;
ans.push_back(x);
while(1)
{
if(x&&q[x-1])
--x,q[x]--,ans.push_back(x);
else if(x!=3&&q[x+1])
++x,q[x]--,ans.push_back(x);
else
break;
}
if(!q[0]&&!q[1]&&!q[2]&&!q[3])
{
cout<<"YES"<<endl;
for(int it:ans)
{
cout<<it<<" ";
}
cout<<endl;
return 0;
}
}
cout<<"NO"<<endl;
return 0;
}
CodeForces - 1265D(贪心+暴力)的更多相关文章
- Codeforces 990 调和级数路灯贪心暴力 DFS生成树两子树差调水 GCD树连通块暴力
A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace ...
- The 10th Shandong Provincial Collegiate Programming Contest H.Tokens on the Segments(贪心+优先级队列 or 贪心+暴力)
传送门 •题意 二维平面上有 n 条线段,每条线段坐标为 $(l_i,i),(r_i,i)$: 平面上的每个整点坐标上都可以放置一枚硬币,但是要求任意两枚硬币的横坐标不相同: 问最多有多少条线段可以放 ...
- CodeForces 712C Memory and De-Evolution (贪心+暴力)
题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...
- CodeForces - 1250B The Feast and the Bus (贪心+暴力)
题意 https://vjudge.net/problem/CodeForces-1250B 每个人属于队伍ai,汽车一次至多载两只队伍(全员),费用为车的容量*载人次数,问最少花费. 思路 k(队伍 ...
- Diverse Garland CodeForces - 1108D (贪心+暴力枚举)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Codeforces 734C [水][暴力][贪心]
题意: 要生产n个物品,每个花费时间为x. 有两种魔法,每种最多使用1个. 其中第一种魔法可以使每个物品生产的花费时间变为ai,相应的花费是bi;第二种魔法可以减少ci个物品,相应的花费是di,并且保 ...
- Karen and Game CodeForces - 816C (暴力+构造)
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...
- CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
随机推荐
- 图形界面GUI
JFrame jframe = new JFrame(); //创建一个窗口 jframe.setVisible(true) //设置窗口显示 jframe.setLocation() //设置窗口位 ...
- nginx编译安装配置模块大全
使用configure命令配置构建.它定义了系统的各个方面,包括允许nginx用于连接处理的方法.最后,它会创建一个Makefile.该configure命令支持以下参数:--help 打印帮助信息. ...
- LightOJ1355 Game Of CS(green 博弈)
Jolly and Emily are two bees studying in Computer Science. Unlike other bees they are fond of playin ...
- ARTS-S C语言主线程获取子线程返回值
#include<stdio.h> #include<stdlib.h> #include <pthread.h> typedef struct { int stu ...
- JsonClassGenerAtor 使用json字符串生成对象
https://pan.baidu.com/s/1Mz1xB6L3blqrRiRAMuJpIg 链接
- 【CuteJavaScript】Angular6入门项目(2.构建项目页面和组件)
本文目录 一.项目起步 二.编写路由组件 三.编写页面组件 1.编写单一组件 2.模拟数据 3.编写主从组件 四.编写服务 1.为什么需要服务 2.编写服务 五.引入RxJS 1.关于RxJS 2.引 ...
- CreateDefaultBuilder方法都做了什么?
当我们创建好一个新的ASP.NET Core Web应用时,系统会使用CreateDefaultBuilder方法,这个方法完成了以下操作: use Kestrel as the web server ...
- VS2017 无法修改代码编辑区的项背景颜色问题
以前都是好好的,安装 ClaudiaIDE: https://github.com/buchizo/ClaudiaIDE 之后也没啥问题,用着用着代码编辑区自定义的颜色就没有了,好几台电脑都是这样, ...
- 一 、爬虫的认识与http
一 .爬虫的认识与http 互联网应用架构 一般采用c/s架构,b/s架构或者m/s架构 c/s 即 client server 客户端 服务端 b/s 即 browser server 浏览器 服 ...
- Promise代码详解(show you the code)
认识异步函数 同步函数: const sum1 =(a,b)=>{ return a+b } console.log('AAA'); console.log(sum(5,6)); conosle ...