POJ-2456Aggressive cows
来源:互联网 发布:最新网络流行歌曲 编辑:程序博客网 时间:2024/05/21 14:52
题意:有N个坐标点,选择其中C个点。要使选择的点的相邻的距离的最小值最大。
思路:根据最小值的性质,枚举最小值。
思路:根据最小值的性质,枚举最小值。
c(x)表示距离的最小值距离为x时,能否找到满足题目的C个点。满足表示x可以更大。不满足,表示x应该更小。
#include <iostream>#include <map>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <queue>#include <stack>#include <functional>#include <set>#include<sstream>#include <cmath>using namespace std;#define pb push_back#define PB pop_back#define bk back()#define fs first#define se second#define INF 1001000#define sq(x) (x)*(x)#define eps (1e-10)#define clr(x) memset((x),0,sizeof (x))#define cp(a,b) memcpy((a),(b),sizeof (b))typedef long long ll;typedef unsigned long long ull;typedef pair<int,int> P;const int maxn=101000;int N,C;int cow[maxn];bool c(int m){ int num=1; int last=cow[0]; for(int i=1;i<N;i++) { if(cow[i]-last>=m) { last=cow[i]; num++; } } return num>=C;}int main(){ scanf("%d%d",&N,&C); for(int i=0;i<N;i++) scanf("%d",&cow[i]); sort(cow,cow+N); int left,right,mid; left=0,right=*max_element(cow,cow+N)+1; while(right-left>1) { mid=(left+right)/2; if(c(mid)) left=mid; else right=mid; } printf("%d\n",left); 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-2456Aggressive cows
- POJ 2456 - Aggressive cows
- POJ 2456 Aggressive cows
- poj 2456 Aggressive cows
- com.google.protobuf.InvalidProtocolBufferException: Message missing required fields: callId, status
- AOP(3)
- mysql 查看binlog 操作日志及恢复数据
- 062 - Unique Paths
- 一张网页从meta标签开始
- POJ-2456Aggressive cows
- 5-4 BCD解密
- 初探CentOS搭建SVN服务器
- java集合:线性表
- angularjs指令link函数参数scope,指令controller依赖注入的$scope,与指令外部controller的$scope的关系
- tomcat7监听端口 改为 80 linux Debian
- Java 1.7 语法新特性
- Wireshark抓取RTP包,还原语音
- 063 - Unique Paths II