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的更多相关文章

  1. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  2. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  3. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  4. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. javaWeb中URLEncoder.encode编码需要调用两次

    今天碰到一个问题,在Controller类中一个方法跳转到该类中的另一个方法,带着中文参数,在跳转之前对该参数进行编码: msg = java.net.URLEncoder.encode(msg,&q ...

  2. ViewData与ViewBag的使用区别

    在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从 ...

  3. Html Ajax上传文件,form表单下载文件

    Html中的代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&quo ...

  4. Struts2的学习链接

    ---- Struts2的学习途径 (downpour) http://www.iteye.com/wiki/struts2/1306-struts2-way-of-learning ---- Str ...

  5. 谷歌C++编程为何禁止缺省参数

    C++的缺省参数尽量不要使用,结果可能出乎我们的意料,下面的程序大家看看输出结果是多少? )                  cout << num << endl;     ...

  6. VHDL之Aggregate

    Definition A basic operation that combines one or more values into a composite value of a record or ...

  7. 基准测试-jmeter压力测试activeMQ之一环境安装配置

    jmeter压力测试activeMQ 摘要:linux(CentOS)单机activeMQ安装.window(2008Server)Jmeter配置activeMQ包.Jmeter配置linux监控 ...

  8. 创建一个dynamics CRM workflow (三) - Creating Configuration Entity for Custom Workflow

    上个帖子中, 我们创建了个发email的workflow. 但是我们邮件当中的tax 值是 hard code, 这在开发当中是不容许的. 那今天我们来把这个build in workflow用 in ...

  9. img标签过滤加fs模块实现图片文件缓存

    方法一:function iCache(selector) { selector.each(function(data) { //msg(data); ! function(data) { var u ...

  10. centos7常见的操作

    centos7的网络IP地址配置文件在  /etc/sysconfig/network-scripts 文件夹下, 查看当前网卡名称 ip ad li ens33网卡对应的配置文件为ifcfg-ens ...