poj2456】的更多相关文章

https://vjudge.net/problem/POJ-2456 二分,从最大长度开始,不断折半试,如果牛全放下了,就是可行,修改下界,否则改上届. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cmath> #include<map> #define lson l,…
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…
题目链接: https://vjudge.net/problem/POJ-2456 题目大意: 有n个牛栏,选m个放进牛,相当于一条线段上有 n 个点,选取 m 个点, 使得相邻点之间的最小距离值最大 解题思路: 二分枚举最小距离的最大值 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; const int INF =…
/* 二分法的应用:最大化最小值 POJ2456 Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18125 Accepted: 8636 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight li…
Aggressive cows 二分,关键是转化为二分! #include <cstdio> #include <algorithm> ; ; int N, C; int a[maxN]; using namespace std; bool judge(int x) { ; ; i < C;i++) { ; while (ctr < N && (a[ctr]-a[s] < x)) { ctr++; } if (ctr==N) { return fa…
Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10078   Accepted: 4988 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,..…
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, Lunit…
题目链接:http://poj.org/problem?id=2456 题意: 有n个呈线性排列的牲畜堋,给出其坐标,有c头牛,求把两头牛的最短距离的最大值. 思路: 先将坐标排个序.两头牛的最短距离最小为0,最大为a[n-1]-a[0].结果一定在这之间,那么就用二分一步步逼近,若m满足要求,则在[m+1,r]之间查找,否则在[l,m-1]之间查找.判断的过程用到贪心的思想.详见代码: #include<cstdio> #include<algorithm> using name…
Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13993   Accepted: 6775 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,..…
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description Farmer John has built a <= N <= ,) stalls. The stalls are located along a straight line at positions x1,...,xN ( <= xi <= ,,,). His C ( <= C &l…