poj 2456 Aggressive cows
来源:互联网 发布:vc socket编程 重连 编辑:程序博客网 时间:2024/05/17 22:15
http://poj.org/problem?id=2456
题意:在n个位置放置c只牛,使得每只牛之间的间距最大,求满足条件的最小间距?
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int NM=100005;int a[NM],n,c;//判断在整个长槽内,间距>=x,是否可以放下c只牛bool getsec(int x){int sec,i,ans;sec=a[0];ans=0;for(i=1;i<n;i++){if(a[i]-sec>=x){ans++;sec=a[i];}if(ans>=c-1) return true;}return false;}int main(){int lf,rg,mid,i;while(~scanf("%d%d",&n,&c)){for(i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);lf=0,rg=a[n-1]-a[0]; //lf=0while(lf<=rg){mid=(lf+rg)>>1;if(getsec(mid)) lf=mid+1;else rg=mid-1;}printf("%d\n",lf-1); //不可以输出:mid}return 0;}
http://poj.org/problem?id=2456
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-2456Aggressive cows
- POJ 2456 - Aggressive cows
- POJ 2456 Aggressive cows
- poj 2456 Aggressive cows
- Shell用法和技巧详解
- C#客户端POST与服务端(Servlet编程)通信问题
- 初学java心得及 所犯的错误
- 在Asp.Net中使用JQueryEasyUI
- Android的ListView
- poj 2456 Aggressive cows
- jquery 点击按钮双向双图轮播
- C指针原理(95)-汇编基础(2)
- github 简单使用教程(更新中...)
- PSTN & PBX
- java企业开发三:struts2+spring3再集成hibernate4
- jquery-学习日记2-细节注意点input文本款blur和change的顺序事件
- LA 3644 并查集
- 原生App vs 移动Web App : 你如何选择