poj 2456 Aggressive cows (二分求最大值)
来源:互联网 发布:judy兔子 知乎 编辑:程序博客网 时间:2024/06/07 14:26
题意:有n间牛房,然后有k头牛,问每头牛最大可以间隔多少。
换了种写法~
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int n,c;const int maxn= 100005;int a[maxn];int ok(int mid){ int num=1,dis=a[0]; for(int i=1;i<n;i++) { if(a[i]-dis>=mid) {num++;dis=a[i];} } if(num>=c) return 1; else return 0;}int main(){ scanf("%d %d",&n,&c); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int l=0,r=a[n-1]+1; int res=0; while(l<=r) { int mid=l+(r-l)/2; if(ok(mid)) {res=mid;l=mid+1;} else r=mid-1; } printf("%d\n",res); return 0;}
0 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 2456 Aggressive cows poj 3258 (二分)
- POJ 2456 Aggressive cows(二分)
- POJ 2456 - Aggressive cows(二分)
- poj 2456 Aggressive cows,二分,最大化最小值
- 【TensorFlow_Fold】计算图连接初探 Diamond计算图调试历程
- android学习笔记(6)
- VR视频直播播放器
- symmetric-tree
- 删除表+闪回删除+查询数据字典+查看回收站删除的表+清空回收站
- poj 2456 Aggressive cows (二分求最大值)
- 解决Ubuntu14.04自带拼音输入问题
- Python操作MySQL数据库的三种方法
- git status 显示中文乱码
- 欢迎使用CSDN-markdown编辑器
- 关于图片
- nginx 在加载thinkphp5的时候 出现404
- 查重
- 对C#Chart控件使用整理