poj 2456 二分 Aggressive cows
来源:互联网 发布:java数组转json字符串 编辑:程序博客网 时间:2024/06/05 03:30
题目链接:http://poj.org/problem?id=2456
Aggressive cows
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8880 Accepted: 4408
Description
Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000).
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?
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
* Line 1: Two space-separated integers: N and C
* Lines 2..N+1: Line i+1 contains an integer stall location, xi
* Lines 2..N+1: Line i+1 contains an integer stall location, xi
Output
* Line 1: One integer: the largest minimum distance
Sample Input
5 312849
Sample Output
3
Hint
OUTPUT DETAILS:
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.
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
USACO 2005 February Gold
代码:
#include <iostream>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <string>#include <string.h>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <stack>#include <iomanip>using namespace std;typedef long long LL;const int INF=0x7fffffff;int N,C;int home[100009];bool c(int d){ int last=0; int cur=last+1; int ct=0; for(int i=0;i<N;i++){ if(home[cur]-home[last]>=d){ last=cur; cur=last+1; ct++; if(ct==C-1)return 1; } else{ cur++; } } return 0;}int main(){ cin>>N>>C; for(int i=0;i<N;i++){ scanf("%d",&home[i]); } sort(home,home+N); int l=0,r=1000000001; int mid; while(r-l>1){ mid=(l+r)/2; if(c(mid)){ l=mid; } else r=mid; } cout<<l<<endl; 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 3258 (二分)
- POJ 2456 Aggressive cows(二分)
- POJ 2456 - Aggressive cows(二分)
- poj 2456 Aggressive cows,二分,最大化最小值
- poj 2456 Aggressive cows(贪心+二分)
- 操作系统之-----信号量机制
- Android SDK 国内下载
- UVa 11488 Hyper Prefix Sets Trie树计算最大公共前缀长度*个数
- CSS3教程:pointer-events属性值详解
- android getExternalStorageDirectory() 和 getExternalStorageState()
- poj 2456 二分 Aggressive cows
- c# textbox响应回车并且去除“咚”的一声
- android--(Bitmap处理较大的位图、缓存位图)
- spring读取applicationContext.xml获得BeanFactory的方法
- 我的第一篇博客
- 第九周项目2-对称矩阵压缩存储的实现与应用(1)
- lightoj 1428(后缀数组)
- mysql字符串查询大小写问题
- android--(图片 双缓存实例)