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 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...
随机推荐
- go get 升级所有
go get -u all go get -u go mod update go get -u full_package_name go get -u github.com/... // ('. ...
- nodeJS进程管理器pm2
pm2是一个带有负载均衡功能的Node应用的进程管理器.当你要把你的独立代码利用全部的服务器上的所有CPU,并保证进程永远都活着,0秒的重载, PM2是完美的. PM2是开源的基于Nodejs的进程管 ...
- Luogu P3938 斐波那契
Luogu P3938 斐波那契 第一眼看到这题,想到的是LCA,于是开始想怎么建树,倒是想出了\(n^{2}\)算法,看了下数据范围,果断放弃 想了想这数据范围,大的有点不正常,这让我想起了当年被小 ...
- 人脸识别源代码Open cv
#include <stdio.h> #include <string.h> #include "cv.h" #include "cvaux.h& ...
- Authentication token manipulation error报错解决办法
Authentication token manipulation error报错解决办法 #参考http://blog.163.com/junwu_lb/blog/static/1916798920 ...
- java在线聊天项目 swt可视化窗口Design 重新设计好友列表窗口 增加菜单栏
增加的菜单栏效果图如下: eclipse 中调整到 swt的design视图下 控件区域选择Menu Controls 将Menu Bar拖动到窗口标题栏 将Cascaded Menu拖动到Menu ...
- Core Animation演示
相关代码展示: - (IBAction)toggleRoundCorners:(id)sender { [CATransaction setDisableActions:![_enableAnimat ...
- 【OS_Linux】三大文本处理工具之sed命令
1.sed命令的简介及用法 sed:即为流编辑器,“stream editor”的缩写.他先将源文件读取到临时缓存区(也叫模式空间)中,再对满足匹配条件的各行执行sed命令.sed命令只针对缓存区中的 ...
- 【Java_多线程并发编程】基础篇——线程状态扭转函数
1. wait() sleep() yield() join()用法与区别 本文提到的当前线程是指:当前时刻,获得CPU资源正在执行的线程. 1.1 wait()方法 wait()方法定义在Objec ...
- Linux内核——进程管理之CFS调度器(基于版本4.x)
<奔跑吧linux内核>3.2笔记,不足之处还望大家批评指正 建议阅读博文https://www.cnblogs.com/openix/p/3262217.html理解linux cfs调 ...