codeforces362B
Petya and Staircases
题意:
一个小男孩要上楼梯,他一次可以走1个台阶或2个台阶或3个台阶,但是有一些台阶是脏的,他不想走在脏台阶上。一共有n个台阶和m个脏台阶,他最开始在第1个台阶上,要走到第n个台阶。问小男孩能不能不踩到脏台阶的前提下走到n个台阶。
Input
The first line contains two integers n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≤ di ≤ n) — the numbers of the dirty stairs (in an arbitrary order).
Output
Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO".
Examples
10 5
2 4 8 3 6
NO
10 5
2 4 5 7 9
YES sol:因为有一步步爬的存在,所以只要不是连续三个及以上的脏的台阶,都可以过去
Ps:特判首尾是脏的情况
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,a[N];
int main()
{
int i;
R(n); R(m);
for(i=;i<=m;i++) R(a[i]);
sort(a+,a+m+);
if(a[]==||a[m]==n) return *puts("NO");
for(i=;i<=m;i++) if(a[i-]+==a[i-]&&a[i-]+==a[i])
{
return *puts("NO");
}
puts("YES");
return ;
}
/*
input
10 5
2 4 8 3 6
output
NO input
10 5
2 4 5 7 9
output
YES
*/
codeforces362B的更多相关文章
随机推荐
- linux内存源码分析 - 内存压缩(实现流程)
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 概述 本文章最好结合linux内存管理源码分析 - 页框分配器与linux内存源码分析 -伙伴系统(初始化和申请 ...
- Generative Adversarial Nets[content]
0. Introduction 基于纳什平衡,零和游戏,最大最小策略等角度来作为GAN的引言 1. GAN GAN开山之作 图1.1 GAN的判别器和生成器的结构图及loss 2. Condition ...
- Java过滤掉字符串中的html标签、style标签、script标签
使用正则表达式 import java.util.regex.Matcher; import java.util.regex.Pattern; public class HTMLSpirit{ pub ...
- Redis中单机数据库的实现
1. 内存操作层 zmalloc 系接口 redis为了优化内存操作, 封装了一层内存操作接口. 默认情况下, 其底层实现就是最简朴的libc中的malloc系列接口. 如果有定制化需求, 可以通过配 ...
- Linux常见问题汇总
Linux问题: ifconfig查看IP地下载报错:bash: ifconfig: commandnotfound 解决方法: 先执行 export PATH="$PATH:/sbin&q ...
- Generalized Power Method for Sparse Principal Component Analysis
目录 重点 算法 这篇文章,看的晕晕的,但是被引用了400多次了,就简单地记一笔. 这个东西,因为\(\ell_1\)范数,所以会稀疏化,当然,和\(\gamma\)有关. 重点 我想重点写的地方是下 ...
- Unique Snowflakes UVA - 11572 (离散化+尺取法)
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...
- p141一致有界原则
1.Mk取sup 为什么只要取∩就好了 不应该是先并后交吗 2.为什么说是闭集?
- 物联网框架ServerSuperIO
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- Python之异常处理(执行python文件时传入参数)
使用sys模块 使用sys模块里的argv参数,用来保存参数值 import sys #sys.argv的作用是获取到运行python文件时,传入的参数 #默认如果运行python文件不传参数,arg ...