BZOJ 4525: [Usaco2016 Jan]Angry Cows 二分
来源:互联网 发布:mac卸载 编辑:程序博客网 时间:2024/06/01 09:23
4525: [Usaco2016 Jan]Angry Cows
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 235 Solved: 164
[Submit][Status][Discuss]
Description
奶牛Bessie设计了一个游戏:“愤怒的奶牛”。游戏的原型是:有一些可爆炸的草堆分布在一条数轴的某些坐标上,玩家用弹弓把一头奶牛发射到数轴上。奶牛砸到数轴上的冲击波会引发附近的草堆爆炸。游戏的目标是玩家用一些奶牛炸掉所有的草堆。
有N个草堆在数轴的不同位置,坐标为x1,x2,….,xn。如果玩家以能量R把奶牛发射到坐标x,就会引爆半径R及以内的的草堆,即坐标范围[x−R,x+R]的草堆都会燃爆。
现在有K头奶牛,每头奶牛的能量都是R,请计算如果要引爆所有的草堆,最小的R是多少?
Input
第一行:2个整数N(1≤N≤50,000)和K(1≤K≤10)。
下面有N行,每行一个整数:x1,x2,…,xn,范围在[0…1,000,000,000]。
Output
输出最小可能的R。
Sample Input
7 2
20
25
18
8
10
3
1
20
25
18
8
10
3
1
Sample Output
5
看完题 想一想 嗯 我要二分
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<map>#include<set>using namespace std;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=10*x+ch-'0';ch=getchar();}return x*f;}inline void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=50100;int n,m,a[N];inline bool check(int x){x<<=1;int now=a[1]+x,use=1;for(int i=1;i<=n;++i){if(now<a[i])use++,now=a[i]+x;if(use>m)return 0;}return 1;}int main(){n=read();m=read();for(int i=1;i<=n;i++)a[i]=read();sort(a+1,a+1+n);int l=1,r=int(5e8)+5;while(l<r){int mid=l+r>>1;if(check(mid))r=mid;else l=mid+1;}print(r);puts("");return 0;}/*7 2202518810315*/
阅读全文
0 0
- BZOJ 4525: [Usaco2016 Jan]Angry Cows 二分
- bzoj4509【Usaco2016 Jan】Angry Cows
- BZOJ4525——[Usaco2016 Jan]Angry Cows
- USACO2016 Jan Bronze 2:Angry Cows
- BZOJ 4509 USACO 2016 Jan Gold Angry Cows
- bzoj 1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏 二分
- BZOJ 4510: [Usaco2016 Jan]Radio Contact dp
- USACO 2016 Jan Silver 愤怒的奶牛(Angry Cows)
- USACO 2016 Jan Gold 愤怒的奶牛(Angry Cows)
- USACO 2016 Jan Bronze 2.Angry Cows 愤怒的奶牛
- 【BZOJ】4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- BZOJ 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- bzoj 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- USACO 2016 JAN——Angry Cows套题的解题报告
- USACO Angry Cows总结
- bzoj4512: [Usaco2016 Jan] Build Gates
- Angry Cows总结_2016.2.28
- 【BZOJ4510】[Usaco2016 Jan]Radio Contact【DP】
- bat 脚本之 使用函数
- Using Predefined CSS Margin Classes
- spring原理
- Linux环境下C++单元测试Gtest 入门
- Tinker原理深入理解(二)
- BZOJ 4525: [Usaco2016 Jan]Angry Cows 二分
- NodeJS -- 异步I/O
- Word2003快速操作技巧及常用快捷键使用
- PowerPC家族谱系详解
- 训练自己的数据,微调faster Rcnn模型
- C++ 实现USB
- laravel:服务提供者的实际应用
- HDP 2.4 离线安装
- Doubango RTP包传输使用UDT可靠传输协议,解决RTP丢包问题