BZOJ——1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏
http://www.lydsy.com/JudgeOnline/problem.php?id=1720
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 177 Solved: 90
[Submit][Status][Discuss]
Description
Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afternoon treats. The corral's edges must be parallel to the X,Y axes. FJ's land contains a total of N (C <= N <= 500) clover fields, each a block of size 1 x 1 and located at with its lower left corner at integer X and Y coordinates each in the range 1..10,000. Sometimes more than one clover field grows at the same location; such a field would have its location appear twice (or more) in the input. A corral surrounds a clover field if the field is entirely located inside the corral's borders. Help FJ by telling him the side length of the smallest square containing C clover fields.
Input
* Line 1: Two space-separated integers: C and N
* Lines 2..N+1: Each line contains two space-separated integers that are the X,Y coordinates of a clover field.
Output
* Line 1: A single line with a single integer that is length of one edge of the minimum size square that contains at least C clover fields.
Sample Input
1 2
2 1
4 1
5 2
Sample Output
OUTPUT DETAILS:
Below is one 4x4 solution (C's show most of the corral's area); many
others exist.
|CCCC
|CCCC
|*CCC*
|C*C*
+------
HINT
Source
求最小的代价,考虑二分(logmaxlen)
发现数据范围支持n^2logmaxlen的复杂度
现将所求正方形看做是一个无限高的矩形,
O(n)枚举一个右端点,确定出左端点后,
再O(n)判断在规定的高度内能否得到C个糖果
#include <algorithm>
#include <cstdio> inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int N();
int c,n;
struct Node {
int x,y;
bool operator < (const Node&a)const
{
return x<a.x;
}
}pos[N]; int L,R,Mid,ans,cnt,tmp[N];
inline bool judge(int l,int r)
{
if(r-l+<c) return ; cnt=;
for(int i=l; i<=r; ++i) tmp[++cnt]=pos[i].y;
std::sort(tmp+,tmp+cnt+);
for(int i=c; i<=cnt; ++i)
if(tmp[i]-tmp[i-c+]<=Mid) return ;
return ;
}
inline bool check(int x)
{
int l=,r=;
for(; r<=n; ++r)
{
if(pos[r].x-pos[l].x>x)
if(judge(l,r-)) return ;
for(; pos[r].x-pos[l].x>x; ) l++;
}
return judge(l,n);
} int Presist()
{
read(c),read(n);
for(int i=; i<=n; ++i)
read(pos[i].x),read(pos[i].y);
std::sort(pos+,pos++n);
for(R=1e4; L<=R; )
{
Mid=L+R>>;
if(check(Mid))
{
R=Mid-;
ans=Mid+;
}
else L=Mid+;
}
printf("%d\n",ans);
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}
BZOJ——1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏的更多相关文章
- 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...
- BZOJ1720:[Usaco2006 Jan]Corral the Cows 奶牛围栏
我对二分的理解:https://www.cnblogs.com/AKMer/p/9737477.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...
- bzoj1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏
金组题什么的都要绕个弯才能AC..不想银组套模板= = 题目大意:给n个点,求最小边长使得此正方形内的点数不少于c个 首先一看题就知道要二分边长len 本来打算用二维前缀和来判断,显然时间会爆,而且坐 ...
- bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan
1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec Memory Limit: 64 MB Description The N (2 & ...
- bzoj:1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in ...
- bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】
几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstri ...
- BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...
- Bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 传递闭包,bitset
1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 323 Solved ...
- 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(tarjan)
http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...
随机推荐
- 关于js作用域问题详解
执行上下文 函数表达式和函数声明 1. console.log(a); // ReferenceError: a is not defined // ReferenceError(引用错误)对象表明一 ...
- python之道06
1,使⽤循环打印以结果: * *** ***** ******* ********* 答案: 方法一: for i in range(10): if i % 2 == 1: print(i*'*') ...
- javascript querySelector和getElementById通过id获取元素的区别
querySelector和getElementById通过id获取元素的区别 <!DOCTYPE html> <html> <head> <meta cha ...
- Fortran学习笔记5(数组Array)
数组的声明方式 一维数组 二维数组 多维数组 数组索引值的改变 自定义类型的数组定义 对数组内容的设置 利用隐含式循环设置数组初值 对整个数组操作 对部分数组的操作 where函数 Forall函数 ...
- 【树链剖分 差分】bzoj3626: [LNOI2014]LCA
把LCA深度转化的那一步还是挺妙的.之后就是差分加大力数据结构了. Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep ...
- vim之替换命令
格式:<range>s /<pat1>/<pat2>/gc <range>用来指定替换命令执行的范围: 百分号(%)表示所有行 点(.)表示当前行 美元 ...
- python基础知识14-正则表达式
1.正则表达式 正则可以代替其他任何工具,但是其他工具不能完全代替正则. 1.匹配或提取字符串的工具,基于所有语言之上的工具. 正则表达式所面向的问题 判断一个字符串是否匹配给定的格式,如判断用户注册 ...
- 在html页面中使用js变量
Method 1: <a id="xxxx">xxxxxxxxxxxxxxxxxx</a> <script type="text/jav ...
- javamail腾讯企业邮箱发送邮件
此代码用的jar文件:mail.jar(1.4.5版本); 如果jdk用的是1.8版本会出现SSL错误:这个问题是jdk导致的,jdk1.8里面有一个jce的包,安全性机制导致的访问https会报错, ...
- iOS-runtime-根据协议名调某一个类有与协议里面放的相同的方法
// // ViewController.m // ObserverTrampoline // // Created by Rob Napier on 9/7/11. // Copyright (c) ...