HDU 4004 The Frog's Games [2011 大连网络赛]
来源:互联网 发布:淘宝旺旺名字能改吗 编辑:程序博客网 时间:2024/05/05 22:05
题意:
青蛙过河,河的宽度是L,给出n个石头的坐标,不存在同一坐标的两个石头( two stone appear in one place is impossible),青蛙最多跳m次,求青蛙应该跳的最大距离中的最小距离。
分析:
二分
//AC CODE:
#include <iostream>#include<algorithm>#include <cstdio>using namespace std;int L,n,m;int dis[500005];int is_ok(int mid)//过河需要跳的最小次数{ int cnt=0,from=0; for(int i=0; i<=n; i++) { if(dis[i]-from<=mid && dis[i+1]-from>mid) { from=dis[i]; cnt++; } } //cout<<mid<<" "<<cnt<<endl; return cnt;}int main(){ int i,mid,ans,maxn; while(scanf("%d %d %d",&L,&n,&m)!=EOF) { for(i = 0 ; i < n ; i ++) scanf("%d",&dis[i]); dis[n]=L; maxn=-1; sort(dis,dis+n+1); for(i=1; i<=n; i++) if(maxn<dis[i]-dis[i-1]) maxn=dis[i]-dis[i-1]; dis[n+1]=2*L;//保证过不了这一点 int beg=maxn,end=L; while(beg<=end) { mid=(beg+end)>>1; if(is_ok(mid)<=m)// <= { end=mid-1; ans=mid; } else// > { beg=mid+1; } } printf("%d\n",ans); } return 0;}
- HDU 4004 The Frog's Games [2011 大连网络赛]
- HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)
- HDU 4004 - The Frog\'s Games 第36届ACM/ICPC亚洲大连赛区网络赛
- 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
- EnumServicesStatusEx貌似有异常
- MOSS数据库服务器迁移步骤
- 关于电涡流传感器灵敏度及加速度传感器灵敏度
- sql语句复习
- .Net设计模式桥接模式(Bridge Pattern)
- HDU 4004 The Frog's Games [2011 大连网络赛]
- 正则表达式
- windows server 2003域控制器的建立(组图)
- 如何从Excel中把数据导入到SharePoint List(Import Excel data to SharePoint List)
- 200多个js技巧代码
- Java同步机制总结--synchronized
- Windows Message ID
- strawberry是一款基于JavaScript(vml,svg)的Web拓扑图(流程设计器)
- 将焦点从一个对话框移到另一个对话框