poj2456(二分)
来源:互联网 发布:棒球器材知乎 编辑:程序博客网 时间:2024/05/17 23:09
题意:最大化最小值,将m个物体放入n个位置中,使得每个物体的相差的最小值最大;
思路:二分枚举答案,看是否符合
Code:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int maxn = 1e5 + 10;int a[maxn];int n,m;bool is_(int d){ int temp = a[1],cnt = 1; for(int i = 2; i <= n; i ++) { if(a[i] - temp >= d) { cnt ++; temp = a[i]; } } if(cnt >= m) { return true; } return false;}int main(){ while( ~ scanf("%d%d",&n,&m)) { for(int i = 1; i <= n; i ++) scanf("%d",&a[i]); sort(a+1,a+n+1); int l = 1,r = a[n] - a[1]; int T = 60; while(T --) { int mid = (l + r) >> 1; if(is_(mid)) { l = mid; } else r = mid; } cout << l << endl; } return 0;}
阅读全文
0 0
- POJ2456 二分
- POJ2456 二分
- POJ2456【二分】
- poj2456(二分)
- poj2456(贪心+二分)
- POJ2456 Aggressive cows (二分)
- poj2456 二分搜索
- poj2456(二分搜索)
- POJ2456 Aggressive cows 二分
- nyoj586||poj2456 二分+贪心
- POJ2456 二分搜索
- nyoj586 poj2456二分+贪心
- Poj2456二分+贪心
- POJ2456 Aggressive cows(二分+贪心)
- poj2456二分搜索最大化最小值
- POJ2456 Aggressive cows 二分+判断
- POJ2456 -- Aggressive cows(二分搜索)
- poj2456
- 报文管理新发现功能总结
- indexHtml部分属性
- Python random模块(随机整数部分内容)
- react+react-router+redux开发体育馆管理系统(1)--项目搭建
- 表单自定义验证setCustomValidity
- poj2456(二分)
- Lua面试题目
- 代码重构--Map去除if条件表达式
- js相关
- office——word内容替换、插入
- 什么是一个企业的基因?转型就是转基因
- 简洁版即时聊天---I/O多路复用使用
- FastJson与JackJson忽略属性
- Let's Encrypt从明年年初开始签发通配符证书