BZOJ4723: [POI2017]Flappy Bird
2018-05-22 20:16
176 查看
$n \leq 500000$个水管,每秒横坐标加一,纵坐标如果你点击就+1否则-1,问从$(0,0)$飞到$m$处最少点多少次,或者说明无解。
如果能飞到某个水管的高度区间$[L,R]$,那么答案肯定是:高度每相差2,答案相差1,感性理解或自证不难。
所以只需要记能飞到的高度区间以及最低处答案即可。
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 //#include<set> 5 #include<algorithm> 6 //#include<math.h> 7 //#include<iostream> 8 //#include<time.h> 9 using namespace std; 10 11 #define LL long long 12 int qread() 13 { 14 char c; int s=0,t=1; while ((c=getchar())<'0' || c>'9') (c=='-') && (t=-1); 15 do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*t; 16 } 17 18 //Pay attention to read! 19 20 int n,m; 21 #define maxn 500011 22 int x[maxn],a[maxn],b[maxn]; 23 #define LL long long 24 int main() 25 { 26 n=qread(); m=qread(); 27 for (int i=1;i<=n;i++) {x[i]=qread(); a[i]=qread()+1; b[i]=qread()-1;} 28 29 int L=0,R=0; LL ans=0; 30 for (int i=1;i<=n;i++) 31 { 32 int d=x[i]-x[i-1]; 33 if (L-d>b[i] || R+d<a[i]) {puts("NIE"); return 0;} 34 int nl=max(L-d,a[i]+((L-d-a[i])&1)); R=min(R+d,b[i]-((R+d-b[i])&1)); 35 if (nl>R) {puts("NIE"); return 0;} 36 ans+=(d+nl-L)>>1; L=nl; 37 } 38 printf("%lld\n",ans); 39 return 0; 40 }View Code
相关文章推荐
- [杂题 贪心] BZOJ4723: [POI2017]Flappy Bird
- 4723: [POI2017]Flappy Bird
- BZOJ4723: [POI2017]Flappy Bird
- BZOJ 4723 POI2017 Flappy Bird
- BZOJ 4723: [POI2017]Flappy Bird
- BZOJ4723 [POI2017]Flappy Bird
- [POI2017] Flappy Bird 题解
- 【bzoj4723】 [POI2017]Flappy Bird
- 【BZOJ4723】【POI2017】Flappy Bird
- 【BZOJ】4723 [POI2017] Flappy Bird
- [POI2017] Flappy Bird (思维题)
- BZOJ4723 [POI2017]Flappy Bird
- 《Flappy Bird》为什么这么火
- 100+行HMTL5代码实现flappy bird
- 以Flappy Bird破解为例介绍防止andriod apk反编译方法
- 转一大一孩子的c++实现的flappy bird(应用sdl库)
- 用Phaser来制作一个html5游戏——flappy bird (二)
- 【cocos2dx 3.2】Flappy Bird开发超详细讲解(二)素材准备和屏幕自适应分辨率
- cocos2d-x 3.1 flappy bird 简单学习制作
- 用物理引擎做Flappy Bird