【POI2017||bzoj4726】Flappy Birds

外国人很良心的啊,这题比NOIP那题还简单……

不用管他最后的位置,因为移动的次数肯定是恒定的,所以维护在每一个柱子的位置能飞到的范围,递推下去即可。

#include<bits/stdc++.h>
using namespace std;
int n,x,y,ans,pos;
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
int main(){
    n=read();int ttt=read();
    for(int i=1;i<=n;i++){
        int d=read(),l=read(),r=read();
        pos+=d-x;y-=d-x;x=d;
        if(y<=l){int t=(l+2-y)>>1;pos-=t;y+=t<<1;ans+=t;}
        if(pos<0||y>=r){puts("NIE");return 0;}
        pos=min(pos,(r-1-y)>>1);
    }
    printf("%d
",ans);
}
原文地址:https://www.cnblogs.com/zcysky/p/6875596.html