Problem UVA1616-Caravan Robbers

Accept: 160  Submit: 1156
Time Limit: 3000 mSec

Problem Description

OnceuponatimetherewasagreedyKing who ordered his chief Architect to build a field for royal cricket inside his park. The Kingwassogreedy, thathewouldnotlisten to his Architect’s proposals to build a fieldrightintheparkcenterwithpleasant 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 hasdaredtotouchevenasingletreeinhis 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. YourtaskistohelppoorArchitecttosavehishead,bywritingaprogramthatwillfindthemaximum possible size of the cricket field and its location inside the park to satisfy King’s requirements. Thetaskissomewhatsimplifiedbythefact,thatKing’sparkhasarectangularshapeandissituated onaflatground. Moreover, park’sbordersareperfectlyalignedwithNorth-SouthandEast-Westlines. At the same time, royal cricket is always played on a square field that is also aligned with North-South andEast-Westlines. ArchitecthasalreadyestablishedaCartesiancoordinatesystemandhasprecisely 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 (W,H), 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, butmaybesituatedonitsside. Thecricketfieldmayalsotouchpark’sborder, butshallnotlieoutside 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 N, W, and H, separated by spaces. N (0 ≤ N ≤ 100) is the number of trees in the park. W and H (1 ≤ W,H ≤ 10000) 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 (0 ≤ Xi ≤ W, 0 ≤ Yi ≤ H) 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 P, Q, and L separated by spaces, where (P,Q) 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. Note: This is a sample input and output that corresponds to the park plan that is shown on the picture.
 

 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

题解:本来想用单调栈,一看数据范围,果断枚举,枚举横坐标的两个端点,遍历所有可能的纵坐标,更新答案即可。

 #include <bits/stdc++.h>

 using namespace std;

 const int maxn =  + ;

 int n, r, c;

 struct Tree {
int x, y;
Tree() {}
Tree(int _x, int _y) : x(_x), y(_y) {}
bool operator < (const Tree &a)const {
return y < a.y;
}
}tree[maxn]; int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int iCase;
scanf("%d", &iCase);
bool flag = false;
while (iCase--) {
if (flag) printf("\n");
flag = true;
scanf("%d%d%d", &n, &c, &r);
for (int i = ; i < n; i++) {
scanf("%d%d", &tree[i].y, &tree[i].x);
}
tree[n] = Tree(, );
tree[n + ] = Tree(r, );
n += ;
sort(tree, tree + n); int Max = , ansx = , ansy = ;
for (int i = ; i < n; i++) {
for (int j = i + ; j < n; j++) {
int lx = min(tree[i].x, tree[j].x);
int rx = max(tree[i].x, tree[j].x);
int len = rx - lx, now = ; for (int k = ; k < n; k++) {
if (lx < tree[k].x && tree[k].x < rx) {
int a = tree[k].y - now < len ? tree[k].y - now : len; if (a > Max) {
Max = a;
ansx = lx, ansy = now;
}
now = tree[k].y;
}
} int a = c - now < len ? c - now : len;
if (a > Max) {
Max = a;
ansx = lx, ansy = now;
}
}
} printf("%d %d %d\n", ansy, ansx, Max);
}
return ;
}

UVA1616-Caravan Robbers(枚举)的更多相关文章

  1. UVA 1616 Caravan Robbers 商队抢劫者(二分)

    x越大越难满足条件,二分,每次贪心的选区间判断是否合法.此题精度要求很高需要用long double,结果要输出分数,那么就枚举一下分母,然后求出分子,在判断一下和原来的数的误差. #include& ...

  2. 【习题 8-14 UVA - 1616】Caravan Robbers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二分长度. 显然长度越长.就越不可能. 二分的时候.可以不用管精度. 直接指定一个二分次数的上限就好. 判断长度是否可行.直接用贪心 ...

  3. UVa - 1616 - Caravan Robbers

    二分找到最大长度,最后输出的时候转化成分数,比较有技巧性. AC代码: #include <iostream> #include <cstdio> #include <c ...

  4. UVa 1616 Caravan Robbers (二分+贪心)

    题意:给定 n 个区间,然后把它们变成等长的,并且不相交,问最大长度. 析:首先是二分最大长度,这个地方精度卡的太厉害了,都卡到1e-9了,平时一般的1e-8就行,二分后判断是不是满足不相交,找出最长 ...

  5. NEERC2012

    NEERC2012 A - Addictive Bubbles 题目描述:有一个\(n \times m\)的棋盘,还有不同颜色的棋子若干个,每次可以消去一个同种颜色的联通块,得到的分数为联通块中的棋 ...

  6. UVA1616-Caravan Robbers(二分)

    Problem UVA1616-Caravan Robbers Accept: 96  Submit: 946Time Limit: 3000 mSec Problem Description Lon ...

  7. UVA10570-Meeting with Aliens(枚举)

    Problem UVA1616-Caravan Robbers Accept: 531  Submit: 2490Time Limit: 3000 mSec Problem Description I ...

  8. SCOJ 4484 The Graver Robbers&#39; Chronicles 后缀自动机

    4484: The Graver Robbers' Chronicles 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4484 Descript ...

  9. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

随机推荐

  1. Indy FTP 警告:Only one TIdAntiFreeze can be active in an application

    > Should I use a AntiFreeze component on every form I have a TIdTCPClient > component?  Or is ...

  2. Hadoop日记Day12---MapReduce学习

    一.MapReduce简介 1.1MapReduce概述 MapReduce是一种分布式计算模型,由Google提出,主要用于搜索领域,解决海量数据的计算问题.MR由两个阶段组成:Map和Reduce ...

  3. [转] FastMM、FastCode、FastMove的使用

    http://blog.csdn.net/akof1314/article/details/6524767 FastMM是一个替换Embarcadero Delphi Win32应用程序的快速内存管理 ...

  4. django文件上传下载

    views: def mgmt_files(request): #列出树形目录,上传文件页面 if request.method == 'POST': path_root = "D:\\py ...

  5. django + ngxin + uwsgi 站点部署

    第一步 创建项目启动脚本 # 创建项目启动脚本 vi /etc/init.d/project_name #!/bin/bash # Description: uwsgi manager scripts ...

  6. iOS UITableView的分割线短15像素,移动到最左边的方法(iOS8)

    有好几个朋友问我ios 分割线端了一些 如何解决,于是我就写一篇博客吧.为什么我说是少了15像素呢?首先我们拖拽一个默认的tableview 控件! 看下xcode5 面板的inspector(检查器 ...

  7. 安装JDK+Tomcat,进行环境变量设置,和运行JSP

    系统:windows 7 64-bit 安装前需要用到的软件 JDK7u21 Tomcat 8.0 下载64-bit Windows zip就好 安装JDK7u21 和平常安装软件一样,路径也不要动, ...

  8. PHP MAIL DEMO(程序代码直接发送邮件)

    php代码 <?php // 收件人邮箱地址 $to = 'xxxxxx@qq.com'; // 邮件主题 $title = '测试邮件发送'; // 邮件内容 $msg = '这是一封测试邮件 ...

  9. 创建iwatch 程序选项

    include complication :包含自定义表盘事件 include glance scene:包含缩略图事件

  10. MySQL学习(二)索引与锁 --- 2019年1月

    1.Order By 是怎么工作的 MySQL做排序是一个成本比较高的操作.MySQL会为每个线程分配一个 sort_buffer 内存用于排序,该内存大小为 sort_buffer_size. 全字 ...