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
Sample Input
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(枚举)的更多相关文章
- UVA 1616 Caravan Robbers 商队抢劫者(二分)
x越大越难满足条件,二分,每次贪心的选区间判断是否合法.此题精度要求很高需要用long double,结果要输出分数,那么就枚举一下分母,然后求出分子,在判断一下和原来的数的误差. #include& ...
- 【习题 8-14 UVA - 1616】Caravan Robbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二分长度. 显然长度越长.就越不可能. 二分的时候.可以不用管精度. 直接指定一个二分次数的上限就好. 判断长度是否可行.直接用贪心 ...
- UVa - 1616 - Caravan Robbers
二分找到最大长度,最后输出的时候转化成分数,比较有技巧性. AC代码: #include <iostream> #include <cstdio> #include <c ...
- UVa 1616 Caravan Robbers (二分+贪心)
题意:给定 n 个区间,然后把它们变成等长的,并且不相交,问最大长度. 析:首先是二分最大长度,这个地方精度卡的太厉害了,都卡到1e-9了,平时一般的1e-8就行,二分后判断是不是满足不相交,找出最长 ...
- NEERC2012
NEERC2012 A - Addictive Bubbles 题目描述:有一个\(n \times m\)的棋盘,还有不同颜色的棋子若干个,每次可以消去一个同种颜色的联通块,得到的分数为联通块中的棋 ...
- UVA1616-Caravan Robbers(二分)
Problem UVA1616-Caravan Robbers Accept: 96 Submit: 946Time Limit: 3000 mSec Problem Description Lon ...
- UVA10570-Meeting with Aliens(枚举)
Problem UVA1616-Caravan Robbers Accept: 531 Submit: 2490Time Limit: 3000 mSec Problem Description I ...
- SCOJ 4484 The Graver Robbers' Chronicles 后缀自动机
4484: The Graver Robbers' Chronicles 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4484 Descript ...
- Swift enum(枚举)使用范例
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
随机推荐
- Java中关于Map的使用(HashMap、ConcurrentHashMap)
在日常开发中Map可能是Java集合框架中最常用的一个类了,当我们常规使用HashMap时可能会经常看到以下这种代码: Map<Integer, String> hashMap = new ...
- Docker 系列五(Docker Compose 项目).
一.概念 Docker Compose 是官方编排项目之一,负责快速的部署分布式应用.它允许用户通过一个单独的 docker-compose.yml 模板文件(YAML格式)来定义一种相关联的应用容器 ...
- React.cloneElement
作用: 克隆react element, 并传递props, 和children React.cloneElement( element, [props], [...children] ) // ch ...
- angular 1.2.29版本下 动态添加多个表单、 校验全部、 提交 、ng-form方案
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HTML5为输入框添加语音输入功能
这里介绍的是大家以后要用到的html强大功能,可直接给输入框增加语音功能,下面我们先来看看实现方法. 大家可以看到在输入框右边的麦克风图标,点击麦克风就能够进行语音识别了. 其实很简单,语音识别是ht ...
- BDD实战篇 - .NET Core里跑Specflow - 可以跑集成测试和单元测试
这是<如何用ABP框架快速完成项目 >系列中和DevOps系列文章其中一篇文章. BDD很赞!比TDD先进很多,能够大大提高编码效率. 上一篇文章说了如何在.NET Core里安装 ...
- Spring学习之旅(七)基于XML配置与基于AspectJ注解配置的AOP编程比较
本篇博文用一个稍复杂点的案例来对比一下基于XML配置与基于AspectJ注解配置的AOP编程的不同. 相关引入包等Spring AOP编程准备,请参考小编的其他博文,这里不再赘述. 案例要求: 写一 ...
- 开发Spring过程中几个常见异常(三):java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast to com.edu.aop.ArithmeticCalculatorImpl at com.edu.aop.Main.main(Main.java:11)
这个异常是在开发Spring案例时遇到的. 贴一下完整异常信息: Exception in thread "main" java.lang.ClassCastException: ...
- JPTabBar 详细介绍
一个强大的TabBar,实现市面上APP基本上所拥有的功能,代码简单构造容易!只需不足5行代码就把基本的界面搭建出来了 附上效果图: 主要功能特色: 多种Tab切换的动画效果 实现底部导航中间按钮凸出 ...
- mysql之变量
本文内容: 系统变量 用户变量 局部变量 首发日期:2018-04-18 系统变量: 系统变量就是系统已经提前定义好了的变量 系统变量一般都有其特殊意义.比如某些变量代表字符集.某些变量代表某些mys ...