hdu 4004 The Frog's Games
来源:互联网 发布:萝莉酱llj222备用域名 编辑:程序博客网 时间:2024/05/19 04:02
http://acm.hdu.edu.cn/showproblem.php?pid=4004
分析:二分查找+贪心(哎)
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int NM=500005;int a[NM],n,m;bool Stone(int mid){ int k,t,i,j; i=1;j=k=0; while(i<=n+1) { k++; //需要的跳数 while(a[i]-a[j]<=mid&&i<=n+1) //寻找能跳的最远的石头 i++; j=i-1; }if(k<=m) return 1; else return 0;}int main(){ int L,temp,t,i,mid,high,low; while(scanf("%d%d%d",&L,&n,&m)!=EOF) { for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); a[n+1]=L;a[0]=0; // t=a[1]; for(i=2;i<=n+1;i++) //寻找最大间距 { temp=a[i]-a[i-1]; t=temp>t?temp:t; } if(m>=n+1) //跳数m和石头数+1相同 printf("%d\n",t); else { low=t,high=L; while(low<=high) { mid=(low+high)/2; if(Stone(mid)) high=mid-1; else low=mid+1; } printf("%d\n",low); } } return 0;}
- HDU 4004 THE FROG’S GAMES(二分)
- HDU 4004 The Frog's Games
- hdu 4004 The Frog's Games
- HDU 4004 The Frog's Games
- HDU 4004 The Frog's Games
- HDU 4004 The Frog's Games
- hdu 4004 The Frog's Games
- hdu 4004 The Frog's Games
- HDU 4004 The Frog's Games
- hdu 4004 The Frog's Games
- hdu 4004 The Frog's Games
- HDU 4004 The Frog's Games(二分)
- The Frog’s Games(hdu 4004)
- HDU 4004 The Frog's Games(二分)
- hdu 4004 - The Frog's Games
- HDU 4004 The Frog's Games
- HDU 4004 The Frog's Games
- HDU 4004 The Frog's Games
- libjpeg 详解
- 浅谈COOKIE和SESSION关系和区别等
- stack/queue的使用方法
- onSaveInstanceState和onRestoreInstanceState触发的时机
- 白书上的Treap模板
- hdu 4004 The Frog's Games
- 用interrupt()中断Java线程
- Qt输入法事件 QInputMethodEvent
- php底部运行机制
- chrome crx 打包 存在中文 路径 结果。。。
- 黑马程序员Java笔记——面向对象的亲密接触
- Tomcat:IOException while loading persisted sessions: java.io.EOFException解决
- web.xml 的详解
- hdu - 4704 - Sum(费马小定理)