POJ2456 Aggressive cows 2017-05-11 17:54 38人阅读 评论(0) 收藏
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 13993 | Accepted: 6775 |
Description
His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ want to assign the cows to the stalls, such that the minimum distance between any two of them
is as large as possible. What is the largest minimum distance?
Input
* Lines 2..N+1: Line i+1 contains an integer stall location, xi
Output
Sample Input
5 3
1
2
8
4
9
Sample Output
3
Hint
FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3.
Huge input data,scanf is recommended.
Source
————————————————————————————————————
题目的意思是给出n个坐标,选出n个位置使得最小的距离最大
思路:二分加验证
#include <iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstring>
using namespace std;
#define LL long long int n,k;
int a[100005]; bool ok(int xx)
{
int cnt=1;
int x=a[0];
for(int i=1;i<n;i++)
{
if(a[i]-x>=xx)
{
cnt++;
x=a[i];
}
}
if(cnt>=k)
return 1;
else
return 0; } int main()
{
while(~scanf("%d%d",&n,&k))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int l=1,r=1e9;
int ans=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(ok(mid))
{
l=mid+1;
ans=mid;
}
else
r=mid-1;
}
printf("%d\n",ans); } return 0;
}
POJ2456 Aggressive cows 2017-05-11 17:54 38人阅读 评论(0) 收藏的更多相关文章
- Singleton设计模式 分类: 设计模式 2014-12-03 17:54 59人阅读 评论(0) 收藏
实现方法: public class SingleTon<T> where T : class, new() { protected SingleTon() { } pri ...
- HDU1551&&HDU1064 Cable master 2017-05-11 17:50 38人阅读 评论(0) 收藏
Cable master Time Limit: ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- Cubieboard 开箱和入门 | Name5566 分类: cubieboard 2014-11-08 17:27 251人阅读 评论(0) 收藏
Cubieboard 开箱和入门 2014 年 01 月 29 日 by name5566 Categories: Computer Science, Cubieboard Hello Cubiebo ...
- 多校4-Walk Out 分类: 比赛 2015-08-02 17:15 21人阅读 评论(0) 收藏
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- Emag eht htiw Em Pleh 分类: POJ 2015-06-29 18:54 10人阅读 评论(0) 收藏
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2937 Accepted: ...
- MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏
MessageFlood TimeLimit: 1500ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Well,how do you feel about mobil ...
随机推荐
- ssh 免密码登录,以及 本地和远端用户名不一致 问题
ssh 远程登录 ssh -l u1 u1@192.168.0.7 ssh u1@192.168.0.7 每次远程都要输入 用户名,密码 比较麻烦.所以比较好的是免密码登录 1.安装ssh服务器 su ...
- Electron mouse events 参数解析
1.https://electronjs.org/docs/api/web-contents 2.通常用: monitorEvents(document.body, 'mouse') 检测正常的值: ...
- intellij idea 的安装与简单使用
1.将安装包拷贝到指定目录,特别注意不要有中文路径和空格,路径不要太深 2.点击安装(如果是win10系统要使用管理员权限安装) 3. 4.修改默认安装目录:一般来说我们都不要把软件安装在 ...
- for循环语句输出菱形
for(int a = 5; a > 0 ; a--){ for(int b = 1; b <= a; b++){ System.out.print(" "); } f ...
- 第八章 高级搜索树 (b1)B-树:动机
- Asp.net中判断是否是指定页面请求的代码示例
//获取请求网址,非法请求,返回主页 if (Request.UrlReferrer != null) { string requstUrl = Request.UrlReferrer.Absolut ...
- 转)Ubuntu14安装wireshark进行抓包
转自:http://jingyan.baidu.com/article/c74d60009d992f0f6a595de6.html 背景: ubuntu14.04/64位 为了抓包和分析包 安装过程: ...
- 对于局部变量,text、ntext 和 image 数据类型无效
开发存储过程时报如上错误.大多数人说用varchar(8000)代替text,但值我这里超过8000,不可取 解决: sql2005或以上版本支持新数据类型:varchar(max)nvarchar( ...
- 删除排序数组中的重复数字 II · Remove Duplicates from Sorted Array II
重复一次 [抄题]: 给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度. 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成. [思维问题]: [ ...
- 对ubuntu初学感想
感觉对ubuntu一头雾水...作为什么都不懂得小菜鸟,感觉以后还有很多要学习的.fighting