nyoj586(poj2456) 疯牛
2017-03-29 21:48
141 查看
原题链接:nyoj586 疯牛
北大oj:Aggressive cows
北大oj:Aggressive cows
//贪心+二分 难点:理解题意 #include <stdio.h> #include <algorithm> using namespace std; const int N = 100005; int a , n, c; bool judge(int x) { int cnt = 1, tmp = a[0]; for(int i = 1; i < n; i++) { if(a[i] - tmp >= x) { cnt++; tmp = a[i]; if(cnt >= c) //可以放下C头牛 return true; } } return false; } int get_ans() //二分搜索最小值 { int l = 0, r = a[n-1] - a[0]; while(l <= r) { int mid = (l + r) / 2; if(judge(mid)) l = mid + 1; else r = mid - 1; } return l - 1; //或r } int main() { while(~scanf("%d%d",&n,&c)) { for(int i = 0; i < n; i++) scanf("%d",&a[i]); sort(a, a+n); printf("%d\n",get_ans()); } return 0; }
相关文章推荐
- NYOJ 586 疯牛(贪心+二分)
- NYOJ 586 疯牛
- 疯牛 nyoj 586
- NYOJ-586 疯牛
- nyoj-586-疯牛|poj-2456-Aggressive cows
- nyoj 586 疯牛
- nyoj 586 疯牛和nyoj 619 青蛙过桥 二分枚举+贪心
- POJ 2456 Aggressive cows 和 NYOJ 586 疯牛【二分枚举+贪心】
- NYOJ-586 疯牛
- nyoj 586 疯牛(贪心)
- NYOJ - 586 疯牛
- nyoj586 疯牛
- NYOJ586疯牛(二分查找算法)
- NYOJ 586 疯牛
- NYOJ 586-疯牛(二分)
- nyoj586 疯牛
- NYOJ 586 疯牛(二分 + 贪心)
- nyoj--586(疯牛) && poj --2456
- NYOJ-586 疯牛(二分枚举+贪心)
- NYOJ 586 疯牛(最大化最小值)