hdu 4004 二分+ 贪心 The Frog's Games
2012-08-27 16:48
225 查看
题意:
给一列石头,让你找跳m次所需具备的最小能力,即找那么多种m次跳法中最大距离最小的。
解:
二分找答案,哎,做的时候提醒了才想到。决定去做做几道二分的题目。
给一列石头,让你找跳m次所需具备的最小能力,即找那么多种m次跳法中最大距离最小的。
解:
二分找答案,哎,做的时候提醒了才想到。决定去做做几道二分的题目。
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int l,m,n,dis[500010],ant[500010]; bool go(int dist){ int pre = ant[1]; int num = 1; if(pre > dist) return false; for(int i = 2; i <= n + 1; i ++){ if(pre + ant[i] > dist){pre = ant[i]; num ++;} else pre += ant[i]; if(num > m) return false; } return true; } int main(){ while(~scanf("%d%d%d",&l,&n,&m)){ for(int i = 1; i <= n; i ++) scanf("%d",dis + i); sort(dis + 1, dis + 1 + n); dis[n + 1] = l; dis[0] = 0; int Max = 0; for(int i = 1; i <= n + 1; i ++){ ant[i] = dis[i] - dis[i - 1]; Max = max(ant[i],Max); } // cout << Max << endl; int low = Max, high = l; while(low <= high){ int mid = (low + high) >> 1; if(go(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(2011年大连网络赛 D 二分+贪心)
- 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 (二分+贪心)
- 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(2011年大连网络赛 D 二分+贪心)
- HDU 4004 The Frog's Games(二分+贪心)
- HDU 4004 The Frog's Games(基本算法-贪心,搜索-二分)
- HDU 4004 The Frog's Games (二分 + 贪心 青蛙跳石头)