【poj 2456】 Aggressive cows
来源:互联网 发布:淘宝服装一件代发货源 编辑:程序博客网 时间:2024/06/06 02:32
题意:
FJ建造了一个有
思路:
分析题目的单调性,设距离的最小值是x,假设x非常小,那从n中要选的点的个数y比较大,随着x的增加,要选的点的数量越来越小,所以不难发现,随着x的增加,y单调递减。二分枚举x,找到一个最大的x,使
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll a1[100010], n, m;bool check(ll x){ ll now = a1[1], cnt = 1; for(int i = 2; i <= n; i ++){ if(a1[i] - now < x) continue; now = a1[i], cnt ++; } return cnt >= m;}int main(){ scanf("%lld%lld", &n, &m); for(int i = 1; i <= n; i ++) scanf("%lld", &a1[i]); sort(a1+1, a1+1+n); ll l = 0, r = 1e9, ans = 0; while(l <= r){ ll mid = (l+r)>>1; if(check(mid)) ans = mid, l = mid + 1; else r = mid - 1; } printf("%lld", ans); return 0;}
1 0
- Poj 2456 Aggressive cows
- POJ 2456 Aggressive cows
- poj 2456 Aggressive cows
- poj 2456 Aggressive cows
- POJ-2456-Aggressive cows
- POJ 2456 Aggressive cows
- POJ-2456 Aggressive cows
- poj 2456 Aggressive cows
- POJ 2456 Aggressive cows
- POJ 2456 Aggressive cows
- poj 2456 Aggressive cows
- POJ 2456 Aggressive cows
- POJ 2456 Aggressive cows
- POJ-2456 Aggressive cows
- POJ-2456Aggressive cows
- POJ 2456 - Aggressive cows
- POJ 2456 Aggressive cows
- poj 2456 Aggressive cows
- Android生命周期分析
- Android 通知栏Notification的整合全面学习
- SDL基础-4、渲染与文理(CB)
- CentOs7中 nginx 与 memcache的安装
- linux 让你的进程后台运行
- 【poj 2456】 Aggressive cows
- html标签的嵌套规则
- 第七周 OJ总结<3>-百位数分解
- [kuangbin带你飞]专题六 最小生成树 D POJ 2421
- 输入两个数,进行四则运算
- web前端-JavaScript 错误 -020
- 第八周OJ-求连续倒数和
- Maximal Square
- 二分查找以及冒泡排序