POJ 3258(二分求最大化最小值)
2017-03-30 16:56
405 查看
题目链接:http://poj.org/problem?id=3258
题目大意是求删除哪M块石头之后似的石头之间的最短距离最大。
这道题目感觉大致代码写起来不算困难,难点在于边界处理上。我思考边界思考许久,还是没有弄明白为什么这样写正确,另外的写法就不对。
已知的问题数据是:
题目大意是求删除哪M块石头之后似的石头之间的最短距离最大。
这道题目感觉大致代码写起来不算困难,难点在于边界处理上。我思考边界思考许久,还是没有弄明白为什么这样写正确,另外的写法就不对。
已知的问题数据是:
12 5 4 2 4 6 8 10
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; const int maxn = 50000 + 15; int A[maxn]; int L, N, M; bool C(int k){ int del = 0; int last = 0; for(int i = 1; i <= N + 1; i++){ if(abs(A[i] - A[last])<=k){ del++; } else last = i; } //cout << k << " " << del << endl; return del > M; } int solve(int l, int r){ while(l <= r){ int m = (l + r) >> 1; if(C(m))r = m - 1; else l = m + 1; } /* 2 4 6 8 10 12 1 */ return l; } int main(){ cin >> L >> N >> M; A[0] = 0; for(int i = 1; i <= N; i++){ cin >> A[i]; } A[N+1] = L; sort(A, A + N + 2); cout << solve(0, L) << endl; return 0; }
相关文章推荐
- poj_3258 River Hopscotch(二分求最大化最小值)
- POJ 3258 River Hopscotch(贪心+二分查找 最大化最小值)
- poj 3258 River Hopscotch(二分搜索之最大化最小值)
- 《挑战程序设计竞赛》3.1.1 二分搜索-最大化最小值 POJ1064 2456 3258 3273 3104 3045
- 【贪心专题】POJ 3258 River Hopscotch (最大化最小值 贪心+二分搜索)
- poj 3258 River Hopscotch(二分最大化最小值)
- POJ 3258 River Hopscotch (二分 + 最大化最小值 + 模拟双向链表)
- POJ 3258 River Hopscotch (最大化最小值)二分
- POJ - 3258 River Hopscotch(二分搜索:最大化最小值)
- POJ 3258(二分——最大化最小值)
- poj 3258 River Hopscotch (二分搜索---最大化最小值)
- POJ 3258(二分——最大化最小值)
- POJ 3258 River Hopscotch【二分:最大化最小值】
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
- 【POJ】3258 - River Hopscotch 二分->最大化最小值
- POJ 2456 3258 3273 3104 3045(二分搜索-最大化最小值)
- POJ 3258 River Hopscotch (二分,最大化最小值)
- POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)
- POJ 3258 River Hopscotch(最大化最小值)