hdu 4004 二分+ 贪心 The Frog's Games
来源:互联网 发布:什么翻译软件好 编辑:程序博客网 时间:2024/05/21 15:42
题意:
给一列石头,让你找跳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 ( 二分+贪心 )
- 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 [二分]
- HashSet的个人理解
- Vitamio FAQ
- pyQuery在python中,实现css选择器功能
- Android的framework层音量控制原理分析
- camera摄像原理之二:色彩空间
- hdu 4004 二分+ 贪心 The Frog's Games
- Android模拟器操作
- 2012_08_27android_Camera
- java -Xbootclasspath的用法.
- android面试题总结加强再加强版(二)
- 《推荐系统实践》试读:第一章:好的推荐系统
- camera摄像原理之三:色温和自动白平衡
- 2.一对一单向主键关联(人对身份证) 工具类
- HDU 3401 Trade【单调队列+dp】