洛谷 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*
+------
#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的更多相关文章
- 洛谷 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 ...
随机推荐
- 7-Java-C(四平方和)
题目描述: 四平方和定理,又称为拉格朗日定理: 每个正整数都可以表示为至多4个正整数的平方和. 如果把0包括进去,就正好可以表示为4个数的平方和. 比如: 5 = 0^2 + 0^2 + 1^2 + ...
- uva1352 Colored Cubes LA3401
白书第一章例题8 好麻烦! 正方体每面编号为0-5,那么根据顶点和正面,就能确定形态.一共6*4=24种形态. P[i]表示编号i所在位置.比如P[1]=3,表示第二面转到了第四面. 就可以表示出所有 ...
- Bézier surface(贝塞尔曲面)
Bézier surface(贝赛尔曲面) 贝塞尔曲面是一种用于计算机图形学.计算机辅助设计和有限元建模的数学样条.与贝塞尔曲线一样,贝塞尔曲面由一组控制点定义.与插值在许多方面相似,一个关键的区别是 ...
- css--字体和文本样式
文字样式属性 字体:font-family 文字大小:font-size 文字颜色:font-color 文字粗细:font-weight 文字样式:font-style font-family字体属 ...
- 在Foxmail邮件客户端登录263企业邮箱
一.问题描述 首次用Foxmail登录263企业,输入账号和密码,创建 二.问题分析 客户端配置地址: 协议类型 服务器地址 默认端 加密端(SSL) POP pop.263.net 110 1995 ...
- tab bar controller
下面记一下怎样通过代码的方式为选项卡添加视图. 1.创建一个基于Empty Application的项目 2.创建两个新类,基类选择UIViewController,勾选With XIB for us ...
- CAS机制(多线程)
---- 什么是CAS机制 CAS机制主要是发生于Java中原子操作类(JUC)的底层实现中,其中在CAS机制中包含3个基本参数:内存地址V.旧预期值A.要修改的新值B. 当要更新一个变量的时候,只有 ...
- phpStrom+xdebug调试php
1>xdebug下载 1.1>xdebug官网可以根据phpinfo()源代码来提供对应版本的xdebug,地址:https://xdebug.org/wizard.php 如下截图 1. ...
- 20. Valid Parentheses (python版)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- css 图片等宽等高
html <div class="autoimg"> <img src="xxx.jpg" /> </div> css .a ...