博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷P2862 [USACO06JAN]把牛Corral the Cows
阅读量:4678 次
发布时间:2019-06-09

本文共 2318 字,大约阅读时间需要 7 分钟。

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 41 22 14 15 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
#include
using namespace std;#define maxn 4010int 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

你可能感兴趣的文章
c++primer 第l六章编程练习答案
查看>>
上海秋季HCC小记
查看>>
Illustrator 上色
查看>>
truncate表恢复
查看>>
this关键字的使用
查看>>
Console.Read()、Console.ReadLine()、Console.ReadKey()
查看>>
ecere 编译过程中遇到的问题
查看>>
Cyclone V 与 Avalon-MM资料整理——DE1-SOC学习笔记(1)
查看>>
异常:This application has no explicit mapping for /error, so you are seeing this as a fallback.
查看>>
Flask-SQLAlchemy
查看>>
C# - Generics
查看>>
.NET LINQ 转换数据类型
查看>>
[LGP2791] 幼儿园篮球题
查看>>
170. Two Sum III - Data structure design
查看>>
os & sys
查看>>
Shell 常用命令总结
查看>>
vector
查看>>
用分布式缓存提升ASP.NET Core性能
查看>>
《数据结构》相关题目
查看>>
Codeforces Round #431 (Div. 2) A 水 B 暴力模拟 C 思维
查看>>