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 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...
随机推荐
- python之for (循环)
格式: for 循环 for i in s: print(i) # for 关键字 # i 变量 # in 关键字 # s 可迭代对象 int - bool pass和- # for a in &qu ...
- 《零基础入门学习Python》【第一版】视频课后答案第004讲
1.while语句中,当条件为真时,它会一直循环下去,比如下面的例子,不过可以用Ctral + C来强制结束 while 'C': print("i love you") 2.观察 ...
- 【转】4w+1h 教你如何做用户画像
记得14年开始做用户画像的时候,对于用户画像完全没有概念,以为是要画一幅幅图画,经过两年多的学习和理解,渐渐的总结出了一些方法和技巧,在这里就通过4个W英文字母开头和1个H英文字母开头的单词和大家分享 ...
- django第10天(聚合查询,常用字段)
django第10天 聚合查询 聚合函数的使用场景 单独使用:不分组,只查聚合结果 分组使用:按字段分组,可查分组字段与聚合结果 导入聚合函数 from django.db.models import ...
- 【实验吧】因缺思汀的绕过&&拐弯抹角&&Forms&&天网管理系统
<?php error_reporting(); if (!isset($_POST['uname']) || !isset($_POST['pwd'])) { echo '<form a ...
- c++ heap学习
heap并不属于STL容器组件,它分为 max heap 和min heap,在缺省情况下,max-heap是优先队列(priority queue)的底层实现机制. 而这个实现机制中的max-hea ...
- java中的equals与==的区别
equals是Object类的公共方法,方法内部是用==实现的.但是很多类都重写了equals方法,例如基本数据类型的封装类和String类,重写后比较的是对象的值或者内容是否相同.而==是比较地址, ...
- 【01】markdown语法
[02]段落和换行 一个 Markdown 段落是由一个或多个连续的文本行组成,它的前后要有一个以上的空行(空行的定义是显示上看起来像是空的,便会被视为空行.比方说,若某一行只包含空格和制表符,则该行 ...
- luogu3231 [HNOI2013]消毒
前置技能:poj3041 如果是二维平面有一些方块,这些方块被染了黑色,你每次可以选择 \((x,y)\) 的区域染成白色,代价是 \(\min(x,y)\),问你付出的最小代价 显然我们不会这么染 ...
- Eclipse截取android报错log
Eclipse截取android报错log: 1.前提条件:已安装eclipse 2. LogCat界面设置: Logcat是Android 编程中一个命令行工具,可以用于得到程序的 log 信息,可 ...