zoukankan      html  css  js  c++  java
  • CodeForces 362B Petya and Staircases

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

    思路:对于给定的m个脏序列,先排序后,没有连续的三个数就行。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<cstdlib>
     6 #include<string>
     7 #include<cmath>
     8 #include<vector>
     9 using namespace std;
    10 const int maxn=1e5+7;
    11 const double eps=1e-8;
    12 const double pi=acos(-1);
    13 #define ll long long
    14 #define clc(a,b) memset(a,b,sizeof(a))
    15 
    16 int main()
    17 {
    18     ll n;
    19     int m;
    20     int a[3010];
    21     scanf("%I64d%d",&n,&m);
    22     clc(a,0);
    23     for(int i=1; i<=m; i++)
    24         scanf("%d",&a[i]);
    25     sort(a+1,a+1+m);
    26     if(a[1]==1||a[m]==n)
    27     {
    28         printf("NO
    ");
    29     }
    30     else
    31     {
    32         int flag=0;
    33         for(int i=1; i<=m-2; i++)
    34         {
    35             int j=a[i];
    36             if(j+1==a[i+1]&&j+2==a[i+2])
    37             {
    38                 flag=1;
    39                 break;
    40             }
    41         }
    42         if(flag)
    43             printf("NO
    ");
    44         else
    45             printf("YES
    ");
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    Web API总结
    @Html.Raw() 方法输出带有html标签的字符串
    jQuery
    图与树基础-完全图的判定
    图和树基础-蒜头君旅行
    PAT乙级1008
    PAT乙级1007
    PAT乙级1005
    PAT乙级1001
    前端工程化-webpack简介(一)
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5243815.html
Copyright © 2011-2022 走看看