zoukankan      html  css  js  c++  java
  • codeforces362B

    Petya and Staircases

     CodeForces - 362B 

    题意:

    一个小男孩要上楼梯,他一次可以走1个台阶或2个台阶或3个台阶,但是有一些台阶是脏的,他不想走在脏台阶上。一共有n个台阶和m个脏台阶,他最开始在第1个台阶上,要走到第n个台阶。问小男孩能不能不踩到脏台阶的前提下走到n个台阶。

    Input

    The first line contains two integers n and m (1 ≤ n ≤ 1090 ≤ 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

    Input
    10 5
    2 4 8 3 6
    Output
    NO
    Input
    10 5
    2 4 5 7 9
    Output
    YES

    sol:因为有一步步爬的存在,所以只要不是连续三个及以上的脏的台阶,都可以过去
    Ps:特判首尾是脏的情况
    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0'); return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=3005;
    int n,m,a[N];
    int main()
    {
        int i;
        R(n); R(m);
        for(i=1;i<=m;i++) R(a[i]);
        sort(a+1,a+m+1);
        if(a[1]==1||a[m]==n) return 0*puts("NO");
        for(i=3;i<=m;i++) if(a[i-2]+1==a[i-1]&&a[i-1]+1==a[i])
        {
            return 0*puts("NO");
        }
        puts("YES");
        return 0;
    }
    /*
    input
    10 5
    2 4 8 3 6
    output
    NO
    
    input
    10 5
    2 4 5 7 9
    output
    YES
    */
    View Code
     
  • 相关阅读:
    ajax提交 返回中文乱码问题
    JAVA spring配置文件总结
    缓存线程池的作用
    myclipse里有感叹号的问题,希望可以帮到各位
    html 鼠标样式 鼠标悬停 小手样式
    在div中注入html代码
    发送邮件的几种方法(C#发邮件 和 js前台实现都有)C#后台自动发邮件 js发邮件
    Angular js 复制粘贴
    C# ASP 面试题 2017
    cocos-lua3.17 cocos studio lua动画使用
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10645369.html
Copyright © 2011-2022 走看看