BZOJ4525——[Usaco2016 Jan]Angry Cows
1、题意:给一堆可以的限制长度的区间。。。区间的长度是你控制的。。。但是只有一个长度。。。求最短长度覆盖所有的点
2、分析:发现可以二分。。。那二分吧。。。。。然后我们从头向后扫一遍直接判断能否直接覆盖。。。然后就可以AC了《大赛后一水系列》
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
#define inf 2147483647
#define M 100010
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int a[M];
int n, K;
inline bool check(int x){
int l = 1, o = 0;
for(int i = 1; i <= n; i ++){
if(a[i] - a[l] > x * 2){
o ++;
l = i;
}
}
o ++;
return o <= K;
}
int main(){
n = read(), K = read();
for(int i = 1; i <= n; i ++) a[i] = read();
sort(a + 1, a + n + 1);
int l = 0, r = 1000000000, t = 1000000000;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)) r = (t = mid) - 1;
else l = mid + 1;
}
printf("%d\n", t);
return 0;
}
BZOJ4525——[Usaco2016 Jan]Angry Cows的更多相关文章
- bzoj4525: [Usaco2016 Jan]Angry Cows
二分. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; + ...
- NC24017 [USACO 2016 Jan S]Angry Cows
NC24017 [USACO 2016 Jan S]Angry Cows 题目 题目描述 Bessie the cow has designed what she thinks will be the ...
- USACO2016 January Gold Angry Cows
Angry Cows 题目描述:给出数轴上的\(n\)个整点\((a[i])\),现在要在数轴上选一个位置\(x\)(可以是实数),以及一个半径\(R\),在以\(x\)为中心,半径为\(R\)的范围 ...
- bzoj 4506: [Usaco2016 Jan]Fort Moo
4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...
- bzoj4506: [Usaco2016 Jan]Fort Moo(暴力)
4506: [Usaco2016 Jan]Fort Moo Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 145 Solved: 104[Submi ...
- bzoj4512[Usaco2016 Jan] Build Gates
bzoj4512[Usaco2016 Jan] Build Gates 题意: 某人从农场的(0,0)出发,沿边界到处乱走,走过的地方会留下栅栏,等走完后问要在多少个栅栏上开门才能使整个农场连通,最多 ...
- bzoj4511:[Usaco2016 Jan]Subsequences Summing to Sevens
题目大意:给个序列,求最长的连续子序列使其为7的倍数 又是一道令人欢喜的不用怎么用脑的水题.. 边读入,边计算前缀和 分别保存前缀和%7结果为1,2,3,4,5,6的第一次的位置 然后减一减就知道长度 ...
- bzoj4511: [Usaco2016 Jan]Subsequences Summing to Sevens
前缀和. 设f[i]为前缀和%7=i的第一个点.那么答案就是max(i-f[s[i]%7])了. #include<cstdio> #include<algorithm> #i ...
- [BZOJ4506] [Usaco2016 Jan]Fort Moo(DP?)
传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来, ...
随机推荐
- jQuery 基础(4)jQuery 尺寸
jQuery 尺寸方法jQuery 提供多个处理尺寸的重要方法:width()height()innerWidth()innerHeight()outerWidth()outerHeight()jQu ...
- javascript 字符串加密的几种方法
8进制 /*8进制加密*/ function EnEight(){ var monyer = new Array();var i,s; for(i=0;i<txt.value.length;i+ ...
- Yocto开发笔记之《错误记录》(QQ交流群:519230208)
QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 ============================================== 提问: 1. 怎样修改linu ...
- Objective-C学习笔记类目、协议
不是所有的方法都可以被覆盖的!比如:intValue就不能被覆盖!! 原因正在查找中! 别人的电脑上却可以! 类目.h件 #import <Foundation/Foundation.h> ...
- 【原】textarea 换行之间的转换
在操纵表单的时候,如果你在textarea输入的内容是换行的,如果没有进行相应的装换,你输出的内容是不会跟着一起换行的.如果后台返回给你的数据是带有<br />换行符的, 那么在texta ...
- JavaScript排序算法——堆排序
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Sort 整理
文章.图片参考:http://www.jianshu.com/p/1b4068ccd505?hmsr=toutiao.io&utm_medium=toutiao.io&utm_sour ...
- Java Native Interface Specification
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html http://www.ibm.com/develo ...
- 正则匹配IP
分析 IP地址的长度为32位,分为4段,每段8位,用十进制数字表示,每段数字范围为0~255( 2^8 ),段与段之间用英文句点“.”隔开.例如:某台计算机IP地址为10.11.44.100. IP地 ...
- Python之路【第十篇】Python操作Memcache、Redis、RabbitMQ、SQLAlchemy、
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...