Description

 

Once upon a time there was a greedy King who ordered his chief Architect to build a field for royal cricket inside his park. The King was so greedy, that he would not listen to his Architect's proposals to build a field right in the park center with pleasant patterns of trees specially planted around and beautiful walks inside tree alleys for spectators. Instead, he ordered neither to cut nor to plant even a single tree in his park, but demanded to build the largest possible cricket field for his pleasure. If the Kind finds that the Architect has dared to touch even a single tree in his park or designed a smaller field that it was possible, then the Architect will loose his head. Moreover, he demanded his Architect to introduce at once a plan of the field with its exact location and size.

Your task is to help poor Architect to save his head, by writing a program that will find the maximum possible size of the cricket field and its location inside the park to satisfy King's requirements.

The task is somewhat simplified by the fact, that King's park has a rectangular shape and is situated on a flat ground. Moreover, park's borders are perfectly aligned with North-South and East-West lines. At the same time, royal cricket is always played on a square field that is also aligned with North-South and East-West lines. Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of every tree. This coordinate system is, of course, aligned with North-South and East-West lines. Southwestern corner of the park has coordinates (0, 0) and Northeastern corner of the part has coordinates (WH), where W and H are the park width and height in feet respectively.

For this task, you may neglect the diameter of the trees. Trees cannot be inside the cricket field, but may be situated on its side. The cricket field may also touch park's border, but shall not lie outside the park.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The first line of the input file contains three integer numbers NW, and H, separated by spaces. N ( 0N100) is the number of trees in the park. W and H ( 1WH10000) are the park width and height in feet respectively.

Next N lines describe coordinates of trees in the park. Each line contains two integer numbers Xi and Yi separated by a space ( 0XiW, 0YiH) that represent coordinates of i-th tree. All trees are located at different coordinates.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Write to the output file a single line with three integer numbers PQ, and L separated by spaces, where (PQ) are coordinates of the cricket field Southwestern corner, and L is a length of its sides. If there are multiple possible field locations with a maximum size, then output any one.

Sample Input

1

7 10 7
3 2
4 2
7 0
7 3
4 5
2 4
1 7

Sample Output

4 3 4

Note: This is a sample input and output that corresponds to the park plan that is shown on the picture.

题意:给出一张二维图,上面有n个点,要求你找出一个最大的正方形,其中不能有点。

思路:解决这样的问题,当然是采用暴力的方法,可以这样,枚举这幅图的左区间 L 和右区间 R,如果这个区间之内没有点,那么就可以形成边长为min(R - L,h)的正方形了,如果有,那就从下至上考虑点的影响,每两个点之间就形成了上下区间,不过不要忘记最上面的点与w形成的区间和0与最下面的点形成的区间。

应该要注意到n的数据范围是100,而w,h的数据范围是10000,所以你在枚举左右区间时应该要想到绝对不可能采用h

同样的可以去考虑点对于区间选取的影响,每两个点之间形成一个区间,还要考虑最左边的和最右边的区间

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define REP(i,n) for(int i=1;i<=n;i++)
#define M(a) memset(a,0,sizeof(a));
using namespace std;
const int maxn=+;
int n,w,h;
int idx[maxn];
struct node
{
int x,y;
bool operator < (const node & a) const
{
if(x!=a.x) return x<a.x;
return y<a.y;
}
} eve[maxn]; void Init()
{
M(idx);
scanf("%d%d%d",&n,&w,&h);
eve[].x=,eve[].y=;
idx[]=;
idx[n+]=h; //idx的初始化很重要,是枚举的基础
eve[n+].x=w;
eve[n+].y=h;//同时也必须假设(0,0)和(w,h)各有一点
REP(i,n)
{
scanf("%d%d",&eve[i].x,&eve[i].y);
idx[i]=eve[i].y;
}
} void Work()
{
int ansx=,ansy=,anslen=;
sort(eve+,eve+n+);
sort(idx+,idx+n+);
for(int i=; i<=n; i++)
for(int j=i+; j<=n+; j++)
{
int l=idx[i],r=idx[j],down=,up,ww,hh;
ww=r-l;
for(int k=; k<=n; k++)
{
if(eve[k].y>l&&eve[k].y<r)
{
hh=eve[k].x-down;
if(anslen<min(ww,hh))
{
anslen=min(ww,hh);
ansx=l;
ansy=down;
}
down=eve[k].x;
}
}
hh=w-down;
if(anslen<min(ww,hh))
{
anslen=min(hh,ww);
ansx=l;
ansy=down;
}
}
printf("%d %d %d\n",ansy,ansx,anslen);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
Init();
Work();
if(T) puts("");
}
return ;
}

自然也可以以上下界做枚举,不过一定要清楚输入给出的是x,y坐标,你用x,y却是把它看做行与列,完全不同啊

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=;
struct node
{
int x,y;
bool operator < (const node & a) const
{
return y<a.y;
}
} eve[maxn]; int idx[maxn]; int main()
{
int T;
cin>>T;
while(T--)
{
int n,w,h;
cin>>n>>w>>h;
eve[].x=;idx[]=;
eve[].y=;
for(int i=; i<=n; i++) {cin>>eve[i].y>>eve[i].x;idx[i]=eve[i].x;} //输入的y坐标是行,x坐标是列
eve[n+].x=h;idx[n+]=h;
eve[n+].y=w;
sort(eve+,eve+n+);
sort(idx+,idx+n+);
int maxlen=,maxx=,maxy=;
for(int i=; i<=n+; i++)
for(int j=i+; j<=n+; j++)
{
int down=idx[i],up=idx[j],l=,hi,wi;
hi=up-down;
//cout<<hi<<" "<<idx[i]<<" "<<idx[j]<<endl;
for(int k=;k<=n;k++)
{
if(eve[k].x<=down||eve[k].x>=up) continue;
wi=eve[k].y-l;
if(maxlen<min(wi,hi))
{
maxlen=min(wi,hi);
maxx=down;
maxy=l;
}
l=eve[k].y;
}
wi=w-l;
if(maxlen<min(wi,hi))
{
maxlen=min(wi,hi);
maxx=down;
maxy=l;
}
}
cout<<maxy<<" "<<maxx<<" "<<maxlen<<endl;
if(T) puts("");
}
return ;
}

E - Cricket Field的更多相关文章

  1. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  2. UVa 1312 Cricket Field (枚举+离散化)

    题意:在w*h的图上有n个点,要求找出一个正方形面积最大,且没有点落在该正方形内部. 析:枚举所有的y坐标,去查找最大矩形,不断更新. 代码如下: #include <cstdio> #i ...

  3. UVA 1312 Cricket Field

    题意: 在w*h的坐标上给n个点, 然后求一个最大的矩形,使得这个矩形内(不包括边界)没有点,注意边界上是可以有点的. 分析: 把坐标离散化.通过两重循环求矩形的高,然后枚举,看是否能找到对应的矩形. ...

  4. UVA-1312 Cricket Field (技巧枚举)

    题目大意:在一个w*h的网格中,有n个点,找出一个最大的正方形,使得正方形内部没有点. 题目分析:寻找正方形实质上等同于寻找矩形(只需令长宽同取较短的边长).那么枚举出所有可能的长宽组合取最优答案即可 ...

  5. 【习题 8-19 UVA-1312】Cricket Field

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 添加两个y坐标0和h 然后从这n+2个y坐标中任选两个坐标,作为矩形的上下界. 然后看看哪些点在这个上下界中. 定义为坐标集合S S ...

  6. 【uva 1312】Cricket Field(算法效率--技巧枚举)

    题意:一个 L*R 的网格里有 N 棵树,要求找一个最大空正方形并输出其左下角坐标和长.(1≤L,R≤10000, 0≤N≤100) 解法:枚举空正方形也就是枚举空矩阵,先要固定一个边,才好继续操作. ...

  7. UVA1616-Caravan Robbers(枚举)

    Problem UVA1616-Caravan Robbers Accept: 160  Submit: 1156Time Limit: 3000 mSec Problem Description O ...

  8. WC2021 题目清单

    Day2 上午 <IOI题型与趣题分析> 来源 题目 完成情况 备注 IOI2002 Day1T1 Frog 已完成 IOI2002 Day1T2 Utopia IOI2002 Day1T ...

  9. salesforce 零基础学习(六十二)获取sObject中类型为Picklist的field values(含record type)

    本篇引用以下三个链接: http://www.tgerm.com/2012/01/recordtype-specific-picklist-values.html?m=1 https://github ...

随机推荐

  1. oracle中WMSYS.WM_CONCAT函数的版本差异

    昨天在测试的时候发现,开发人员写的一段程序放在开发库中是好的,但是放在测试库中就会有问题.开发人员一直找不到问题的原因在哪里.于是就花了点时间协助开发人员来找问题的根本原因. 通过一些技术手段,定位到 ...

  2. 关于file文件操作的头文件 【LINUX】 (转载)

    转自:http://blog.csdn.net/figo77ll/article/details/3156052 Linux下如果要对文件进行读取访问,需要包含至少以下两个头文件: #inlcude ...

  3. [App Store Connect帮助]六、测试 Beta 版本(3.1)管理测试员:添加内部测试员

    您可以添加至多 25 个内部测试员(您的 App Store Connect 用户)使用“TestFlight Beta 版测试”来测试您的 App.在您上传了至少一个构建版本之后,才可添加测试员. ...

  4. thinkphp 5 常用的助手函数

    load_trait:快速导入Traits,PHP5.5以上无需调用 /**     * 快速导入Traits PHP5.5以上无需调用     * @param string    $class t ...

  5. BFS(两点搜索) FZOJ 2150 Fire Game

    题目传送门 题意:'#'表示草地,两个人在草地上点火,相邻的草地会烧起来,每烧一格等1秒,问最少要等几秒草地才烧完 分析:这题和UVA 11624 Fire!有点像,那题给定了两个点,这题两点不确定, ...

  6. BFS POJ 3414 Pots

    题目传送门 /* BFS:六种情况讨论一下,BFS轻松解决 起初我看有人用DFS,我写了一遍,TLE..还是用BFS,结果特判时出错,逗了好长时间 看别人的代码简直是受罪,还好自己终于发现自己代码的小 ...

  7. 发生在升级OS X Yosemite后:修复各种开发环境

    本博文最初发布于我的个人博客<Jerry的乐园> 终于还是忍不住升级了,促使我升级的原动力居然是Alfred的Yosemite theme居然比初始theme好看很多!在升级前就预想到我的 ...

  8. RabbitMQ一:消息队列的认识

    1异步处理 场景说明:用户注册后,需要发注册邮件和注册短信.传统的做法有两种1.串行的方式:2.并行方式. (1)串行方式:将注册信息写入数据库成功后,发送注册邮件,再发送注册短信.以上三个任务全部完 ...

  9. HTML+CSS 基础布局(案列一)

    刚html刚讲完马上就接着css,周末的任务就是高仿案例,结果有点遭 图文布局 代码 css(内部样式) html <!DOCTYPE html><html><head& ...

  10. mysql timeout expired处理

    一.发现问题 二.分析问题 .net长时间连接mysql导致超时: 方式一:连接用完后,就关闭连接 方式二:增加C#的执行sqlcommand时间 三.解决问题 增加了这一句,问题解决了 using ...