HDU 4004 The Frog's Games [二分]
来源:互联网 发布:overture mac 破解版 编辑:程序博客网 时间:2024/05/21 08:52
二分法找答案
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int MAXN = 500000 + 9;int l, n, m;int a[MAXN];bool ok(int x){ //cout << x << endl; int s = 0; //开始跳的点 int i = 1; //要跳到的点 int total = 0; while (i <= n + 1) { if (a[i] - a[s] > x) return false; while (i <= n + 1 && a[i] - a[s] <= x) { i++; } total++; s = i - 1; } if (total <= m) return true; return false;}void solve(){ a[0] = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } a[n + 1] = l; sort(a, a + n + 2); int p = 0, q = l; while(p < q) { int mid = (p + q) / 2; if(ok(mid)) q = mid; else p = mid + 1; } printf("%d\n", q);}int main(){ //freopen("in.txt", "r", stdin); while (scanf("%d%d%d", &l, &n, &m) != EOF) { solve(); }}
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<二分>
- Hdu 4004 The Frog's Games(二分)
- HDU 4004 The Frog's Games 二分+贪心
- hdu 4004The 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 (二分搜索 + 贪心)
- SpringMVC学习笔记
- js的原型继承
- 用 Selenium 自动化验收测试
- java中Map集合的常用遍历方法及HashMap的应用实例
- 决策树(二)--C4.5
- HDU 4004 The Frog's Games [二分]
- 查看电脑配置信息
- Android静态安全检测 -> logcat可能泄露隐私敏感信息
- C++STL之string
- linux--时间编程(5)
- C++STL之string
- 纯新手向--Linux搭建SVN服务器
- Word Pattern
- hdu1429 胜利大逃亡(续)--BFS