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<iostream>
#include<cstdio>
using namespace std;
#define maxn 4010
int map[maxn][maxn],c,n,sum[maxn][maxn],N,M;
int main(){scanf("%d%d",&c,&n);int x,y;for(int i=1;i<=n;i++){scanf("%d%d",&x,&y);map[x][y]++;N=max(N,x);M=max(M,y);}int range=max(N,M);for(int i=1;i<=range;i++)for(int j=1;j<=range;j++)sum[i][j]=sum[i-1][j]+sum[i][j-1]+map[i][j]-sum[i-1][j-1];for(int i=1;i<=range;i++)//正方形的边长 for(int j=i;j<=range;j++)for(int k=i;k<=range;k++)if(sum[j][k]-sum[j-i][k]-sum[j][k-i]+sum[j-i][k-i]>=c){printf("%d",i);return 0;}
}

30分 只用前缀和维护了一下

转载于:https://www.cnblogs.com/thmyl/p/7420287.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. 集合70多种推荐算法,东北大学老师用Java写了一个开源库,在GitHub上收获近1500个Star...
  2. 目标检测分割--Mask R-CNN
  3. python培训出来的有公司要吗-参加Python培训到底需要学什么?好程序员
  4. 如何使用 python 减少 kaggle Mushroom Classification 数据集中的特性数量?
  5. 选择图像的“感兴趣区域”
  6. c语言继承机制的作用,计算机二级C++强化试题及答案
  7. 为什么 APP 纷纷开发“暗黑模式”?优酷最佳实践总结
  8. POJ - 2411 Mondriaan's Dream(状压dp)
  9. CCNA配置试验之七 PPP中PAP和CHAP的验证
  10. 使用FastReport报表工具生成报表PDF文档
  11. Ubuntu上配置SQL Server Always On Availability Group
  12. Java中map关于putAll()和“=”的区别
  13. 1确认自己的python版本
  14. TIOBE 9 月编程语言:C++ 突起、Java 流行度下降
  15. Using Cobbler Web Interface
  16. PE格式第七讲,重定位表
  17. python竞赛试题及答案_【技术分享】用python解NOIP竞赛题
  18. 【CCNA学习实录】二进制 十进制 十六进制 VLSM
  19. Twitter数据非API采集方法
  20. 不想被瓶颈必须了解的计算机基础

热门文章

  1. 计算机三大科学理论是,近代科学最伟大的三大理论:进化论、量子论和计算论...
  2. 1709 - Index column size too large. The maximum column size is 767 bytes.
  3. 动态加载so库的实现方法与问题处理
  4. 使用即时通讯(IM)SDK心得体验
  5. Python内置容器(2)——字典,迭代器,列表解析
  6. soltrace教程(3)基本使用
  7. 正则表达式判断ip格式
  8. MS CRM 2011 汇总更新4已经发布
  9. python 序列类型函数_序列类型可用的内置函数
  10. Linux应用编程基础04:Linux线程编程