nyoj-586-疯牛|poj-2456-Aggressive cows
http://acm.nyist.net/JudgeOnline/problem.php?pid=586
http://poj.org/problem?id=2456
解题思路:最大化最小值二分答案即可
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int a[];
6 int n, c, i;
7
8 int cmp(const void *a, const void *b){
9 return *(int *)a - *(int *)b;
}
bool check(int x){
int cnt = , temp = a[];
for(i = ; i < n; i++){
if(a[i] - temp > x){
cnt++;
temp = a[i];
if(cnt >= c){//如果能装下c头牛
return true;
}
}
}
return false;
}
void solve(){
//二分搜索最大的距离
int l = , r = a[n - ] - a[];
while(l <= r){
int mid = (l + r) >> ;
if(check(mid)){
l = mid + ;
}
else{
r = mid - ;
}
}
printf("%d\n", l);
}
int main(){
while(scanf("%d %d", &n, &c) != EOF){
for(i = ; i < n; i++){
scanf("%d", &a[i]);
}
qsort(a, n, sizeof(a[]), cmp);
solve();
}
return ;
49 }
nyoj-586-疯牛|poj-2456-Aggressive cows的更多相关文章
- poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...
- 二分搜索 POJ 2456 Aggressive cows
题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmat ...
- POJ 2456 Aggressive cows (二分 基础)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7924 Accepted: 3959 D ...
- POJ 2456 Aggressive cows (二分)
题目传送门 POJ 2456 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) s ...
- [ACM] poj 2456 Aggressive cows (二分查找)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5436 Accepted: 2720 D ...
- POJ 2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11192 Accepted: 5492 ...
- POJ 2456 Aggressive cows(二分答案)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...
- POJ - 2456 Aggressive cows 二分 最大化最小值
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18099 Accepted: 8619 ...
- poj 2456 Aggressive cows 贪心+二分
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25944 Accepted: 11982 ...
- POJ 2456 Aggressive cows(贪心 + 二分)
原题链接:Aggressive cows 题目大意:农夫 建造了一座很长的畜栏,它包括 个隔间,这些小隔间依次编号为. 但是, 的 头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...
随机推荐
- node中的url模块解析结果
1. URL模块作用: url 模块用于处理与解析 URL. 使用方法如下: const url = require('url'); 2. URL 字符串与 URL 对象 URL 字符串是结构化的字符 ...
- HDU5920【模拟】
模拟题这种东西啊~就是自己读题,自己打,没有别的方法...贴份6000+b的code跑: #include <bits/stdc++.h> using namespace std; //t ...
- 进击python第一篇:相遇
1.第一句Python代码 在 当前目录下创建 hello.py 文件,内容如下: print "hello,world!" 执行 hello.py 文件,即: python he ...
- Aandroid 解决apk打包过程中出现的“Certificate for <jcenter.bintray.com> doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的问题
有时候,apk打包过程中会出现“Certificate for <jcenter.bintray.com> doesn't match any of the subject alterna ...
- Windows下MySQL8.0.13解压版安装教程
下载 MySQL8.0.13-64位下载地址 在下载页面的底部,有三种安装包,第一种是MySQL的安装程序,下载完点击安装即可. 第二种是普通的压缩版,体积较小. 第三种是自带debug和测试的压缩版 ...
- 有趣的JS存储 连等问题
五个月不见了,你是不是和我一样又帅了,今天我们先来看一道经典的关于JS存储的题目,来一场紧张又刺激的脑内吃鸡大战吧: var a = {n:1}; a.x = a = {n:2}; console.l ...
- IP服务-5-网络时间协议
NTP版本3(RFC1305)允许IP主机向一个通用的时钟源同步它们的日期和时间. 从设计上来说,大多数路由器和交换机都使用NTP客户端模式,根据NTP服务器所提供的时间来调整自己的时钟.NTP定义了 ...
- Single-use Stones Codeforces - 965D
https://codeforces.com/contest/965/problem/D 太神仙了...比E难啊.. 首先呢,根据题意,可以很容易的建出一个最大流模型 就是每个位置建一条边,容量限制为 ...
- UG 常用设置
Q01:UG制图,添加基本视图之后的中心线怎么去掉? A01:“菜单-->文件-->首选项-->制图-->视图-->公共-->常规-->□带中心线创建”,取消 ...
- ruby 正则匹配返回值matchdata
引用连接: 为处理与正则表达式的匹配过程相关的信息而设置的类. 可以通过下列途径 Regexp.last_match Regexp#match, String#match $~ 得到该类的实例. 超类 ...