题解:P5957 [POI 2017] Flappy Bird
chase_the_light · · 题解
非常地朴素。
首先考虑我们从上一个点跳到现在这个点需要点击的次数,记为
考虑记录我们前面剩下来的能用的时间为
判断完无解之后更新
up=min(t-need,up+(b-nowy-1)>>1);
接下来就很好写了。
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e5+5;
int n,ans,X,up,nowx,nowy;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>X;
for(int i=1,x,a,b;i<=n;i++){
cin>>x>>a>>b;
nowy-=(x-nowx);
int need=(a-nowy+2)>>1,t=x-nowx+up;
need=max(need,0);
if(nowy+(need<<1)>=b||t<need){
cout<<"NIE";
return 0;
}
nowy+=(need<<1);
up=min(t-need,up+(b-nowy-1)>>1);nowx=x;
ans+=need;
}
cout<<ans;
return 0;
}