UVA - 10043 Chainsaw Massacre
Description
Problem E: Chainsaw Massacre |
Background
As every year the Canadian Lumberjack Society has just held its annual woodcutting competition and the national forests between Montreal and Vancouver are devastated. Now for the social part!In order to lay out an adequate dance floor for the evening partythe
organizing committee is looking for a large rectangular area without trees. Naturally, all lumberjacks are already drunk and nobody wants to take the risk of having any of them operate a chainsaw.
The Problem
The organizing committee has asked you to find the largest yet freerectangle which could serve as the dance floor. The area inwhich you should search is also rectangular and the dance floor mustbe entirely located in that area.Its sides should be parallel to
the borders of the area.It is allowed that the dance floor is located at the borders of the areaand also that trees grow on the borders of the dance floor.What is the maximum size of the dance floor?
The Input
The first line of the input specifies the number of scenarios. For each scenario, the first line provides the length
l and widthw of the area in meters (,both integers). Each ofthe following lines describes either a single
tree, or a line of treesaccording to one of the following formats:
1 x y
, where the ``one'' characterizes a single tree, and x and
y provide its coordinates in meters with respect to the upper leftcorner.k x y dx dy
, where k>1 provides the number of trees in a line withcoordinates
.0
denotes the end of the scenario.
The coordinates x, y, dx, and dy are given as integers. It is guaranteed that all the trees are situated in the area, i.e. have coordinatesin
.There will be at most 1000 trees.
The Output
For each scenario print a line containing the maximum size of the dance floor measured in square meters.
Sample Input
2
2 3
0
10 10
2 1 1 8 0
2 1 9 8 0
0
Sample Output
6
80
题意:平面上有n棵树。找出一个内部没有树的,面积最大的矩形
思路:以y坐标排序然后扫描。每次先扫到一棵树就能够知道它与上一棵树之间的距离,然后更新统计每一个x坐标的最左边和最右边,每次都计算一次
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
const int maxn = 10010; int h[maxn], l[maxn], r[maxn];
int n, m, ans;
map<int, vector<int> > tree; void check() {
for (int i = 0, j = n; i <= n; i++, j--) {
for (l[i] = i; l[i] > 0 && h[l[i]-1] >= h[i]; )
l[i] = l[l[i]-1];
for (r[j] = j; r[j] < n && h[r[j]+1] >= h[j]; )
r[j] = r[r[j]+1];
}
} void cal() {
for (int i = 0; i <= n; i++) {
int tmp = h[i] * (r[i] - l[i] + 2);
ans = max(ans, tmp);
}
} int main() {
int t;
scanf("%d", &t);
while (t--) {
tree.clear();
scanf("%d%d", &n, &m);
int op, x, y, dx, dy;
while (1) {
scanf("%d", &op);
if (op == 0)
break;
else if (op == 1) {
scanf("%d%d", &x, &y);
tree[y].push_back(x);
}
else {
scanf("%d%d%d%d", &x, &y, &dx, &dy);
for (int i = 0; i < op; i++) {
tree[y].push_back(x);
y += dy, x += dx;
}
}
}
tree[m];
ans = max(n, m);
int last = 0;
memset(h, 0, sizeof(h));
map<int, vector<int> >::iterator it;
for (it = tree.begin(); it != tree.end(); it++) {
int d = it->first - last;
last += d;
for (int i = 1; i < n; i++)
h[i] += d;
check();
cal();
vector<int> tmp = it->second;
for (int i = 0; i < tmp.size(); i++)
h[tmp[i]] = 0;
}
printf("%d\n", ans);
}
return 0;
}
UVA - 10043 Chainsaw Massacre的更多相关文章
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
随机推荐
- [WebServer] Linux下Apache与Tomcat整合的简单方法
Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由to ...
- ASP.NET MVC上传文件 未显示页面,因为请求实体过大。解方案
在Dropzone中设置 maxFilesize: 350, //MB 但上传的文件没有到最大限定350MB,就报出来 未显示页面,因为请求实体过大的错误 Web.config中设置 maxAl ...
- A - A Compatible Pair
Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...
- Solr.NET快速入门(四)【相似查询,拼写检查】
相似查询 此功能会返回原始查询结果中返回的每个文档的类似文档列表. 参数通过QueryOptions的MoreLikeThis属性定义. 示例:搜索"apache",为结果中的每个 ...
- Npgsql使用入门(一)【搭建环境】
首先去官网下载最新数据库安装包 postgresql-9.6.1-1-windows-x64 将postgreSQL9.6注册为windows服务 注意:大小写要正确 D:\Worksoftware\ ...
- 【android】RxJava1原理解析
在网络层,互联网提供所有应用程序都要使用的两种类型的服务,尽管目前理解这些服务的细节并不重要,但在所有TCP/IP概述中,都不能忽略他们: 无连接分组交付服务(Connectionless Packe ...
- 1.Ventuz 介绍
Ventoz能做什么? Ventuz是一款实时图文包装内容创作.制作和播出控制软件.Ventuz专注于高端视听内容的制作,包括交互展示和大型活动.视频墙.广播电视在线包装及演播室舞台及灯光控制等领域. ...
- JavaScript私有方法
some concepts: Java is from Sun Microsystem Inc., and JavaScript, called LiveScript before, is from ...
- RAP开发入门-主题更换
通过配置扩展点修改应用主题 ps:需要提前准备好主题(theme.css)文件 <!-- 注册主题扩展点 --> <extension point= ...
- 04-手把手教你把Vim改装成一个IDE编程环境(图文)
Linux下编程一直被诟病的一点是: 没有一个好用的IDE, 但是听说Linux牛人, 黑客之类的也都不用IDE. 但是对我等从Windows平台转移过来的Coder来说, 一个好用的IDE是何等的重 ...