洛谷——P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows
题目描述
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.
约翰打算建一个围栏来圈养他的奶牛.作为最挑剔的兽类,奶牛们要求这个围栏必须是正方 形的,而且围栏里至少要有C< 500)个草场,来供应她们的午餐.
约翰的土地上共有C<=N<=500)个草场,每个草场在一块1x1的方格内,而且这个方格的 坐标不会超过10000.有时候,会有多个草场在同一个方格内,那他们的坐标就会相同.
告诉约翰,最小的围栏的边长是多少?
输入输出格式
输入格式:
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.
输出格式:
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.
输入输出样例
说明
Explanation of the sample:
|* *
| * *
+------Below is one 4x4 solution (C's show most of the corral's area); many others exist.
|CCCC
|CCCC
|*CCC*
|C*C*
+------
什么?!这道题做过?!啊啊啊、、、蒟蒻表示忘记了、、、
http://www.cnblogs.com/z360/p/7641389.html
二分答案
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 5010
using namespace std;
int c,n,mid,ans,tmp[N];
int read()
{
,f=;char ch=getchar();
;ch=getchar();}
+ch-',ch=getchar();
return x*f;
}
struct Node
{
int x,y;
}node[N];
int cmp(Node a,Node b){return a.x<b.x;}
int work(int l,int r)
{
<c) return false;
;
for(int i=l;i<=r;i++)
tmp[++sum]=node[i].y;
sort(tmp+,tmp++sum);
for(int i=c;i<=sum;i++)
]<=mid) return true;
return false;
}
int pd(int x)
{
,r;
;r<=n;r++)
{
if(node[r].x-node[l].x>x)
{
)) return true;
while(node[r].x-node[l].x>x) l++;
}
}
if(work(l,n)) return true;
return false;
}
int main()
{
c=read(),n=read();
;i<=n;i++)
node[i].x=read(),node[i].y=read();
sort(node+,node++n,cmp);
,R=;
while(L<=R)
{
mid=(L+R)>>;
,R=mid-;
;
}
printf("%d",ans);
;
}

距 NOIp2017 还剩 16 天
你可以做的事情还有很多,即使到最后一秒也不要放弃,因为不到结束的那一刻谁也不知道结果会怎样
洛谷——P2862 [USACO06JAN]把牛Corral the Cows的更多相关文章
- 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- 洛谷P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- 洛谷 P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- 洛谷[USACO06JAN]把牛Corral the Cows
题目描述 约翰打算建一个围栏来圈养他的奶牛.作为最挑剔的兽类,奶牛们要求这个围栏必须是正方 形的,而且围栏里至少要有C< 500)个草场,来供应她们的午餐. 约翰的土地上共有C<=N< ...
- [luoguP2862] [USACO06JAN]把牛Corral the Cows(二分 + 乱搞)
传送门 可以二分边长 然后另开两个数组,把x从小到大排序,把y从小到大排序 枚举x,可以得到正方形的长 枚举y,看看从这个y开始,往上能够到达多少个点,可以用类似队列来搞 其实发现算法的本质之后,x可 ...
- 洛谷P1522 [USACO2.4]牛的旅行 Cow Tours
洛谷P1522 [USACO2.4]牛的旅行 Cow Tours 题意: 给出一些牧区的坐标,以及一个用邻接矩阵表示的牧区之间图.如果两个牧区之间有路存在那么这条路的长度就是两个牧区之间的欧几里得距离 ...
- 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom-强连通分量(Tarjan)
本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写 ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom
传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...
随机推荐
- ADB push 和ADB pull命令
adb push命令 :从电脑上传送文件到手机: adb pull命令 :从手机传送文件到电脑上
- linux备忘录-文件系统管理
Extx 文件系统原理 block group 每个分区(partition)的组成为 boot sector -> block group -> block group -> bl ...
- HDU 4027 Can you answer these queries(线段树 + 观察 )
这题主要考察观察能力. 2^63最多只需要开7次根号就会变成1,当数字变成1之后就不需要再对其进行操作. 对于含有大于1数字的区间,向下更新. 对于数字全为1的区间,直接返回. #include &l ...
- 解决:spring security 登录页停留时间过长 跳转至 403页面
前言:最近的项目中用到了spring security组件,说句显low的话:我刚开始都不知道用了security好不勒,提了bug,在改的过程中,遇到了一些问题,找同事交流,才知道是用的securi ...
- Android的WebView有哪些坑?
今天逛知乎的时候,看到一个有关Android应用开发中,WebView 的问题,算是开发中比较常见的问题了吧,而且赞同数比较多的答案,确实回答得还不错,这里小编就整理了一下,分享出来大家借鉴借鉴,避免 ...
- DB2设置code page(日文943)
为了便于 DB2 在执行 DB2 命令或语句之后显示错误.警告和指示性消息,必须安装您期望使用的语言的 DB2 消息文件集.因为 DB2 有基于语言分组的不同分发版,您必须验证安装 CD-ROM 上有 ...
- java中TCP总结
先看一张图,画的很挫,将就看. TCP 客户端与服务端通信时,是服务端会拿到客户端的socket进行通信. TCP就相当于以前的座机,有一个听筒和一个话筒,A用话筒说话,B用听筒听. 下面讲讲java ...
- 《R语言实战》读书笔记--第四章 基本数据管理
本章内容: 操纵日期和缺失值 熟悉数据类型的转换 变量的创建和重编码 数据集的排序,合并与取子集 选入和丢弃变量 多说一句,数据预处理的时间是最长的……确实是这样的,额. 4.1一个示例 4.2创建新 ...
- bzoj 3507 DP+哈希
[Cqoi2014]通配符匹配 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 541 Solved: 235[Submit][Status][Dis ...
- canvas2D 基础知识 浅析
1.canvas HTML5给出的一个可以展示绘图内容的标签 使用领域: (推荐网站:threejs.org) 1. 游戏 2. 可视化数据 3. Banner广告 4. 多媒体 (1)在 c ...