哈理工oj 1006 River Hopscotch
来源:互联网 发布:js调用手机软键盘事件 编辑:程序博客网 时间:2024/06/05 19:16
点击打开链接
AC代码 如下:
#include <stdio.h>#include <cstring>#include <algorithm>#include <cmath>#include <iostream>using namespace std;///二分搜索答案,最大化最小值int main(){ int L,n,m; int a[50010]; while(~scanf("%d %d %d",&L,&n,&m)) { for(int i = 1; i <= n; i++) scanf("%d",&a[i]); a[0] = 0; a[n+1] = L; sort(a,a+n+2); int l = 0,r = L,mid; ///先模拟一个最小值mid,假设它就是正确答案 int num; while(l <= r) { int last = 0; int sum = 0; mid = (l + r) / 2; for(int i = 1; i <= n+1; i++) { if(a[i] - a[last] < mid)//如果比mid小,就将该节点强制删除,并计数 sum++; else last = i;//如果不是就更新,为啥要更新,如果不更新,那我们计算的就不是两点之间的距离了啊
} if(sum > m)///删多了,说明mid值偏大 r = mid - 1; else { l = mid + 1; num = mid; } } //最后经过二分循环,得到最大的mid; printf("%d\n",num); } return 0;}
0 0
- 哈理工oj 1006 River Hopscotch
- River Hopscotch
- River Hopscotch
- River Hopscotch
- River Hopscotch
- River Hopscotch
- Pku oj 3258 River Hopscotch(二分搜索)
- pku 3258 River Hopscotch
- pku3258 River Hopscotch
- pku 3258 River Hopscotch
- poj 3258 River Hopscotch
- Dichotomy poj River Hopscotch
- poj-3258 River Hopscotch
- River Hopscotch解题报告
- poj-3258 River Hopscotch
- POJ3258:River Hopscotch
- poj 3258 River Hopscotch
- POJ3258-River Hopscotch
- 读C#委托与事件笔记
- hdu1045FireNet
- PHP,.net,Java的区别
- Android API Guides---Camera
- hdoj 1872稳定排序
- 哈理工oj 1006 River Hopscotch
- 事件拦截机制分析
- POJ - 1631 Bridging signals
- springMVC+freeMarker表单验证
- mac上使用genymotion
- Windbg实用手册
- 仿QQ底部退出弹出框
- 递归转换循环
- 剑指Offer--021-支持min操作的栈