/* 二分法的应用:最大化最小值 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 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…
Aggressive cows http://poj.org/problem?id=2456 N间小屋,M头牛,使得牛跟牛之间的距离最远,以防止牛打架. 2<=N<=100000 2<=M<=N 0 <=xi<=109 ////////////////////////////////////////////////////////////// C(d):=可以安排牛的位置使得任意两头牛的间距都不小于d 使用二分搜索法解决: //参考文献:挑战程序设计大赛(第二版)/**…
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: 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,..…
链接:http://poj.org/problem?id=2456 题意:一个数轴上n个点,每个点一个整数值,有c个奶牛,要放在这些点的某几个上,求怎么放可以使任意两个奶牛间距离的最小值最大,求这个最大值. 思路:仍然是最大化最小值,套路一样,二分最小距离,每次check即可 AC代码: #include<iostream> #include<vector> #include<cstdio> #include<algorithm> #include<c…
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 二分,从最大长度开始,不断折半试,如果牛全放下了,就是可行,修改下界,否则改上届. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cmath> #include<map> #define lson l,…
如果C(d)为满足全部牛之间的距离都不小于d. 先对牛舍的位置排序,然后二分枚举d,寻找满足条件的d. #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector&…
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/problem.php?pid=586 poj : http://poj.org/problem?id=2456 思路: 二分答案,从前到后依次排放m头牛的位置,检查是否可行 代码: #include <iostream> #include <algorithm> #include &…