zoukankan      html  css  js  c++  java
  • bzoj 4723 [POI2017]Flappy Bird 模拟

    [POI2017]Flappy Bird

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 482  Solved: 196
    [Submit][Status][Discuss]

    Description

    《飞扬的小鸟》是一款风靡的小游戏。在游戏中,小鸟一开始位于(0,0)处,它的目标是飞到横坐标为X的某个位置
    上。每一秒,你可以选择点击屏幕,那么小鸟会从(x,y)飞到(x+1,y+1),或者不点击,那么小鸟会飞到(x+1,y-1)
    。在游戏中还有n个障碍物,用三元组(x[i],a[i],b[i])描述,表示在直线x=x[i]上,y<=a[i]或者y>=b[i]的部分
    都是障碍物,碰到或者擦边都算游戏失败。请求出小鸟从(0,0)飞到目的地最少需要点击多少次屏幕。
     

    Input

    第一行包含两个整数n(0<=n<=500000),X(1<=n<=10^9)。
    接下来n行,每行三个整数x[i],a[i],b[i](0<x[i]<X,-10^9<=a[i]<b[i]<=10^9)。
    数据保证x[i]<x[i+1]。
     

    Output

    如果无论如何都飞不到目的地,输出NIE,否则输出点击屏幕的最少次数。
     

    Sample Input

    4 11
    4 1 4
    7 -1 2
    8 -1 3
    9 0 2

    Sample Output

    5

    HINT


    Source

    鸣谢Claris上传

    题解:发现小鸟的运动范围是知道的,然后记录一下范围,到达一个点,的点击次数是确定的

    然后如果当前的范围没有了,说明不可以通过了。

     1 #include<cstring>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<cmath>
     6 #include<map>
     7 #include<map>
     8 
     9 #define M 500500
    10 using namespace std;
    11 inline int read()
    12 {
    13     int x=0,f=1;char ch=getchar();
    14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    15     while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    16     return x*f;
    17 }
    18 
    19 int n,X,ans;
    20 struct abcd{
    21     int x,a,b,limit;
    22     void Input()
    23     {
    24         scanf("%d%d%d",&x,&a,&b);
    25         a++;b--;
    26         limit = a-x;
    27         if(limit&1) ++limit;
    28     }
    29 }a[M];
    30 
    31 int main()
    32 {
    33     n=read(),X=read();
    34     for(int i=1;i<=n;i++)
    35         a[i].Input();
    36     for(int i=n-1;i>0;i--)
    37         a[i].limit = max(a[i].limit , a[i+1].limit);
    38     int x=0,y=0;
    39     for(int i=1;i<=n;i++)
    40     {
    41         int temp=(y-x)-a[i].limit>>1;
    42         if(temp<0) temp=0;
    43         temp=a[i].x-x-temp;
    44         if(temp<0) temp=0;
    45         y+=temp;y-=a[i].x-x-temp;
    46         x=a[i].x;
    47         if(y<a[i].a || y>a[i].b)
    48             return cout<<"NIE"<<endl,0;
    49         ans+=temp;
    50     }
    51     printf("%d
    ",ans);
    52 }
  • 相关阅读:
    hdu 3790 最短路径问题
    hdu 2112 HDU Today
    最短路问题 以hdu1874为例
    hdu 1690 Bus System Floyd
    hdu 2066 一个人的旅行
    hdu 2680 Choose the best route
    hdu 1596 find the safest road
    hdu 1869 六度分离
    hdu 3339 In Action
    序列化和反序列化
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8759413.html
Copyright © 2011-2022 走看看