题目描述

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.

输入输出样例

输入样例#1: 复制

3 4
1 2
2 1
4 1
5 2
输出样例#1: 复制

4

说明

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*

+------

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int c,n,l,r,mid;
struct nond{
int x,y;
}v[];
bool judge(){
int bns=,cns=,dns=,ens=;
for(int i=;i<=n;i++){
int tx1=v[i].x,dx1=v[i].x+mid-;
int ty1=v[i].y,dy1=v[i].y+mid-;
int tx2=v[i].x-mid+,dx2=v[i].x;
int ty2=v[i].y-mid+,dy2=v[i].y;
int tx3=v[i].x,dx3=v[i].x+mid-;
int ty3=v[i].y-mid+,dy3=v[i].y;
int tx4=v[i].x-mid+,dx4=v[i].x;
int ty4=v[i].y,dy4=v[i].y+mid-;
for(int j=;j<=n;j++){
if(v[j].x>=tx1&&v[j].x<=dx1&&v[j].y>=ty1&&v[j].y<=dy1)
bns++;
if(v[j].x>=tx2&&v[j].x<=dx2&&v[j].y>=ty2&&v[j].y<=dy2)
cns++;
if(v[j].x>=tx3&&v[j].x<=dx3&&v[j].y>=ty3&&v[j].y<=dy3)
dns++;
if(v[j].x>=tx4&&v[j].x<=dx4&&v[j].y>=ty4&&v[j].y<=dy4)
ens++;
}
if(bns>=c||cns>=c||dns>=c||ens>=c) return true;
bns=;cns=;dns=;ens=;
}
return false;
}
int main(){
//freopen("testdata.in","r",stdin);
scanf("%d%d",&c,&n);
for(int i=;i<=n;i++)
scanf("%d%d",&v[i].x,&v[i].y);
l=;r=;
while(l<=r){
mid=(l+r)/;
if(judge()) r=mid-;
else l=mid+;
}
cout<<l;
}

70分

https://www.luogu.org/problemnew/solution/P2862

std

洛谷 P2862 [USACO06JAN]把牛Corral the Cows的更多相关文章

  1. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  2. 洛谷——P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  3. 洛谷P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  4. 洛谷[USACO06JAN]把牛Corral the Cows

    题目描述 约翰打算建一个围栏来圈养他的奶牛.作为最挑剔的兽类,奶牛们要求这个围栏必须是正方 形的,而且围栏里至少要有C< 500)个草场,来供应她们的午餐. 约翰的土地上共有C<=N< ...

  5. [luoguP2862] [USACO06JAN]把牛Corral the Cows(二分 + 乱搞)

    传送门 可以二分边长 然后另开两个数组,把x从小到大排序,把y从小到大排序 枚举x,可以得到正方形的长 枚举y,看看从这个y开始,往上能够到达多少个点,可以用类似队列来搞 其实发现算法的本质之后,x可 ...

  6. 洛谷P1522 [USACO2.4]牛的旅行 Cow Tours

    洛谷P1522 [USACO2.4]牛的旅行 Cow Tours 题意: 给出一些牧区的坐标,以及一个用邻接矩阵表示的牧区之间图.如果两个牧区之间有路存在那么这条路的长度就是两个牧区之间的欧几里得距离 ...

  7. 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party

    P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  8. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom-强连通分量(Tarjan)

    本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写 ...

  9. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom

    传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...

随机推荐

  1. Android主题更换换肤

    知识总览android主题换肤通常借助LayoutInflater#setFactory实现换肤. 换肤步骤: 通过解析外部的apk压缩文件,创建自定义的Resource对象去访问apk压缩文件的资源 ...

  2. [Redis] 基于redis的分布式锁

    前言分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的分布式锁.本篇博客将介绍第二种方式,基于Redis实现分布式锁. 可靠性首先,为了确保 ...

  3. element-ui date-picker 设置结束时间大于等于开始时间且开始时间小于等于结束时间

    Part.1  问题 date-picker 组件在使用时,默认对时间是没有限制的,可以随便选择区间,官方文档添加了快捷选项,如:一周丶一月... 但是从用户体验方面出发,我们还是希望对时间进行有利的 ...

  4. DedeCMS文章标题长度最全修改方法

    有时候DedeCMS首页或者其他页面不能全部展示文章标题,造成读者阅读体验差.一般来说标题精简.概括性强.有本文关键词就是一个好标题.写软文不比写“作文”,也不是论坛的标题党,软文是用来做排名的,主要 ...

  5. Calling method 'get' is not valid without an active transaction

    在进行使用注解来配置Spring和Hibernate的整合的时候, 遇到了这个问题, 它的意思是说在调用'get'方法的时候,没有活动的事务. 原因分析: Hibernate强制要求在进行数据库操作的 ...

  6. centos7下LVM挂载和扩容

    说明:此操作在centos7下进行,如果是centos6发行版,需要注意格式化LV的文件系统类型(centos7.0开始默认文件系统是xfs,centos6是ext4).最后一步写入系统的类型,其中文 ...

  7. 企业支付宝账号开发接口教程--JAVA-UTF-8(实际操作完善中...SpringMVC+JSP)

    关于即时到账的开发.审核通过.简单测试如下. 希望看的可以收藏或者赞一下哦. 1:拥有自己的支付宝企业账号.去产品商店选择适合自己的方案.并签约合同. 2:选择合适的商家收款产品并去签约.填写相应的信 ...

  8. qemu-img命令

    qemu-img是QEMU的磁盘管理工具,在qemu-kvm源码编译后就会默认编译好qemu-img这个二进制文件.qemu-img也是QEMU/KVM使用过程中一个比较重要的工具,本节对其用法和实践 ...

  9. 条款30:透彻了解inline的里里外外(understand the ins and outs of inlining)

    NOTE: 1.将大多数inline限制在小型 被频繁调用的函数身上.这可使日后的调试过程和二进制升级(binary upgradability)更容易,也可使潜在的代码膨胀问题最小化, 使程序的速度 ...

  10. 为什么在属性中设置private set

    引言: 属性的引入来自C#的封装机制,也就是说对象的内部数据不应该由对象实例来直接访问,我们可以使用传统的Get和Set方法,来封装字段,C#为我们提供了语法糖,也就是属性.属性包括get和set,分 ...