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.

输入输出样例

输入样例#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[501];
bool judge(){int bns=0,cns=0,dns=0,ens=0;for(int i=1;i<=n;i++){int tx1=v[i].x,dx1=v[i].x+mid-1;int ty1=v[i].y,dy1=v[i].y+mid-1;int tx2=v[i].x-mid+1,dx2=v[i].x;int ty2=v[i].y-mid+1,dy2=v[i].y;int tx3=v[i].x,dx3=v[i].x+mid-1;int ty3=v[i].y-mid+1,dy3=v[i].y;int tx4=v[i].x-mid+1,dx4=v[i].x;int ty4=v[i].y,dy4=v[i].y+mid-1;    for(int j=1;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=0;cns=0;dns=0;ens=0;}return false;
}
int main(){//freopen("testdata.in","r",stdin);scanf("%d%d",&c,&n);for(int i=1;i<=n;i++)scanf("%d%d",&v[i].x,&v[i].y);l=0;r=10010;while(l<=r){mid=(l+r)/2;if(judge())    r=mid-1;else l=mid+1;}cout<<l;
}

70分

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

std

转载于:https://www.cnblogs.com/cangT-Tlan/p/9884566.html

洛谷 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. 信息学奥赛一本通 1343:【例4-2】牛的旅行 | 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours

    [题目链接] ybt 1343:[例4-2]牛的旅行 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours [题目考点] 1. 图论 最短路径 Floyd算法 Floyd算法时间复杂度 ...

  7. 【USACO06JAN POJ3179】Corral the Cows

    POJ 洛谷 分析 离散化+前缀和+二分 这题和激光炸弹很像,但由于坐标范围较大,需要用到二分. 代码 #include <cstdio> #include <cstring> ...

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

    稍微学习一下强连通分量. https://www.cnblogs.com/stxy-ferryman/p/7779347.html 我觉得他讲得很好. 1 #include <cstdio> ...

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

    题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...

最新文章

  1. ios 圆形旋转菜单_iOS 圆环菜单
  2. [译]在CUDA C/C++中如何衡量代码性能
  3. docker mysql开机自启动_Docker学习4-学会如何让容器开机自启服务【坑】
  4. [html] 说说你对WEB标准和W3C的理解与认识?
  5. 信息学奥赛一本通(1083:计算星期几)
  6. Django Ajax发送请求使用方法
  7. RabbitMQ-AMQP术语介绍
  8. 2018年10月底新公司
  9. NLP技术在金融资管领域的落地实践
  10. 如何在Linux操作系统查看文件创建时间
  11. PayPal支付(Java开发)完整版
  12. 使用Keras基于RCNN类模型的卫星/遥感地图图像语义分割
  13. iOS屏幕旋转及其基本适配方法
  14. angular学习-数据绑定
  15. B站有哪些值得Java初学者看的视频,Java学习路线
  16. 新手如何进行PLC的远程上下载和编程调试?
  17. 你还用60款下架侵害用户权益APP吗!!!!!
  18. java 蓝桥杯 奇怪的数列
  19. 微信支付之微信内H5调起支付
  20. STM32关于PVD低电压能检测的知识

热门文章

  1. 【服务器数据恢复】断电导致存储raid6阵列瘫痪的数据恢复案例
  2. 三星成功秘诀:它何以抗衡苹果
  3. iPhone越狱检测
  4. DiDi Food中的智能补贴实战漫谈
  5. 腾讯与360诉讼陷入拉锯战:敬畏同时余火未熄
  6. 【射频知识】PCB材料/层叠/信号注入设计与传输线实现形式的性能比对
  7. 计算机切换输入法Word关闭,电脑office编辑文字输入法快捷键不能切换怎么办
  8. Bayesian Face Revisited A Joint Formulation
  9. windows下的ntsd命令
  10. ISE综合工具XST综合约束相关