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' 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. mybatis_13一级缓存

    1. Mybatis的缓存理解 Mybatis的缓存,包括一级缓存和二级缓存,一级缓存是默认使用的.二级缓存需要手动开启. 一级缓存指的就是sqlsession,在sqlsession中有一个数据区域 ...

  2. Android Studio 学习(五)网络

    HttpURLConnection OkHttp 添加依赖 编辑 app/build.gradle 在dependencies闭包中添加 implementation 'com.squareup.ok ...

  3. 51单片机:IO口扩展芯片用法(74HC165,74HC595)

    IO口扩展芯片,主要是解决单片机IO口太少. 74HC165:数据从并转串 74HC595:数据从串转并 两种芯片,都是通过时序电路,加上移位功能,进行数据传输 74HC165:数据从并转串.以下实例 ...

  4. 关于python当中的@修饰符的浅析

    https://blog.csdn.net/class_brick/article/details/81170697     要了解python中@装饰器的作用,首先要记住这么几点: 1. 装饰器符号 ...

  5. neutron 多租户隔离的实现以及子网间路由的实现

    1.一个network相当于一个二层网络,使用vxlan 隧道连通所有的CNA节点. 2.一个VPC下有多个network,也就是会分配多个vxlan隧道,这些子网间的路由是通过DVR实现的.DVR就 ...

  6. Android通过Chrome Inspect调试WebView的H5 App出现空白页面的解决方法(不需要FQ)

    本文系博主原创,未经许可不得转载.如未经本人同意,私自转载或盗取资源提供下载,本人保留追究其法律责任的权利. 调试基于WebView的Hybrid App最舒服的工具当然是Chrome自带的开发者工具 ...

  7. (网页)java数组去重总结(转)

    转自CSDN: 1.背景 根据不同的业务逻辑,经常会遇到数组中存在多个重复元素的场合,总结了下数组的排序,留个记录. 2.实现方法   总结了四种方法,接下来进行展示 1.方法一 //数组去重方法一 ...

  8. awesomium_v1.6.6_sdk 百度云下载地址

    awesomium的官网已经关闭很久了,所以找不到正规的下载地址. 而csdn上面的又收费.所以这里提供一个不收费的百度云的下载地址给大家. 不足就是不是1.7版本,所以对于某些有特殊用途的满足不了了 ...

  9. vi中的全局替换

    一.基本语法 替换命令语法: :[addr]s/源字符串/目标字符串/[option] 全局替换: :%s/源字符串/目标字符串/g 参数说明: [addr]--表示检索范围,省略时表示当前行. &q ...

  10. asp.net core 发布到 docker 容器时文件体积过大及服务端口的配置疑问

    在 asp.net core 发布时,本人先后产生了3个疑问. 1.发布的程序为什么不能在docker容器中运行 当时在window开发环境中发布后,dotnet xxx.dll可以正常运行:但放入d ...