【POJ】3258
来源:互联网 发布:软件汉化工具 编辑:程序博客网 时间:2024/06/06 10:05
http://poj.org/problem?id=3258
从N块石头中移除M块,使得间距最小值最大。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int maxn=50005;int n,m,L;int dis[maxn];bool check(int mid){ //最小值 int now=0; int cnt=0; int i=1; while (i<=n+1){ if (dis[i]-dis[now]>=mid){ i++; now=i-1; } else { i++; cnt++; } } if (cnt<=m) return true; //<=m说明最小值还可以更大 else return false; }int main(){ cin >> L >> n >> m; for (int i=1;i<=n;i++){ cin >> dis[i]; } dis[0]=0; dis[n+1]=L; sort(dis,dis+n+1); int l=0,r=1000000005; int mid; while (l+1<r){ mid=(l+r)/2; if (check(mid)) l=mid; else r=mid; } cout << l << endl;}
阅读全文
0 0
- poj 3258
- POJ 3258
- POJ 3258
- poj 3258
- poj 3258
- POJ 3258
- POJ-3258
- poj 3258
- POJ 3258
- 【POJ】3258
- poj 2456 Aggressive cows poj 3258 (二分)
- POJ 3258 二分算法
- poj 3258 River Hopscotch
- poj 3258(二分。。。)
- poj-3258 River Hopscotch
- poj-3258 River Hopscotch
- poj 3258 二分 过河
- poj 3258 还是二分
- HDU 6172 Array Challenge(打表+矩阵快速幂)——2017 Multi-University Training Contest
- 栈的反转、滑动窗口、数组变树
- MAC删除打开方式中重复的软件
- MySQL索引背后的数据结构及算法原理
- CentOS7下Let's Encrypt Nginx配置SSL证书
- 【POJ】3258
- 图表 chart.js
- 【Mybatis升级版-02】mybatis与Spring整合service及controller
- Java冒泡排序
- Android开发中数据库(sqlite)的查看及一些问题的解决方法
- linux指令
- iOS 获取WIFI,IP地址,
- Vue笔记------ 组件(二)
- python学习备忘