HDU 4004 The Frog's Games (二分贪心)
来源:互联网 发布:单片机做扫地机器人 编辑:程序博客网 时间:2024/05/21 09:14
二分答案,每次贪心尽量跳远去判断即可
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 500005;int L, n, m, a[N];bool judge(int mid) { int s = 0; int cnt = 0; while (s != n) { for (int i = s + 1; i <= n + 1; i++) { if (a[i] - a[s] > mid) { if (s == i - 1) return false; s = i - 1; cnt++; if (cnt > m) return false; break; } } } return true;}const int INF = 0x3f3f3f3f;int main() { while (~scanf("%d%d%d", &L, &n, &m)) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); a[++n] = L; a[n + 1] = INF; int l = 0, r = L; while (l < r) { int mid = (l + r) / 2; if (judge(mid)) r = mid; else l = mid + 1; } printf("%d\n", l); } return 0;}
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 [二分]
- RecycleBin原理解析,带你领会ListView的View重用机制
- JAVA练习-第3天 有关异常处理的学习
- Qt5 在win7上发布 & 打包依赖dll生成exe方法
- HDU 4041 Eliminate Witches!(模拟)
- ubuntu中安装apache ab命令进行简单压力测试
- HDU 4004 The Frog's Games (二分贪心)
- HDU 4046 Panda(线段树)
- Qt发布opencv的工程需配置的lib,dll和include等
- HDU 4054 Hexadecimal View(模拟)
- HDU 4055 Number String(dp)
- HDU 4006 The kth great number(优先队列)
- git review (四)
- static_cast与dynamic_cast转换
- ADO.Net Connectivity using Stored Procedure and Output parameters