hdu 4004 The Frog's Games 二分+贪心
来源:互联网 发布:数据库和数据源的关系 编辑:程序博客网 时间:2024/05/17 09:32
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004
题意:一条长L,(1<= L <= 1000000000).(的河上有n,(0<= n <= 500000)个石子,青蛙最多能条m,(1<= m <= n+1)次。求青蛙过河单次跳跃的最小距离。
思路:二分跳跃的最小距离,然后贪心判断是否能跳过。
#include <iostream>#include<bits/stdc++.h>using namespace std;int a[550000],n,m,L;int ok(int k){ int num=1,last0=a[0],last1=a[1]; for(int i=2;i<=n+1;i++) { if(a[i]-last0<=k) last1=a[i]; else if(a[i]-last1<=k) { last0=last1; last1=a[i]; if(++num>m) return 0; } else return 0; } return 1;}int main(){ while(~scanf("%d%d%d",&L,&n,&m)) { a[0]=0,a[n+1]=L; for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a,a+n+2); int l=0,r=L,ans=L; while(l<=r) { int mid=(l+r)>>1; if(ok(mid)) ans=mid,r=mid-1; else l=mid+1; } cout<<ans<<endl; }}
0 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 二分+贪心
- 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 [二分]
- linux下管道问题
- Nircmd命令速查 与 速用,配合PowerPro使用
- ImageLoader加载图片
- Android官方数据绑定框架DataBinding
- 349. Intersection of Two Arrays
- hdu 4004 The Frog's Games 二分+贪心
- java.lang.NoSuchMethodException: MapReduce.WordCount$MyMapper.<init>()
- Spring4+SpringMVC4+Jackson2+Hibernate4+Quartz2+Plupload2+Proxool0.9集成
- 神经网络图灵机(Neural Turing Machines, NTM)
- 在MySql中如何定义像Java中类型的Boolean类型
- char码值对应列表
- 关于Angularjs1.x dom ready
- oracle 调用函数
- yo aspnet