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. No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty planning

    No control record for Activity type 1000/4220/1442 in version 000 / 2017 activity planning/qty plann ...

  2. 单元测试之Mock

    为什么需要Mock. 真实对象具有不确定的行为.所以会产生不可预测的结果. 真实对象很难被创建. 真实对象的某些行为很难被触发(如网络错误). 真实对象令程序的运行速度很慢. 真实对象有(或者是)用户 ...

  3. FlappyBird模拟(不完整版本)

    FlappyBird模拟(不完整版本) 准备材料 land地 sky天 pipe管道 bird小鸟 Land.js function Land(info) { this.x = info.x; thi ...

  4. Java基础8一面向对象

    一.JavaBean标准的定义规范 1.类中所有的属性必须是私有的,也就是说属性必须用private修饰. 2.提供一个公共无参数的构造方法. 3.为所有私有的属性提供公共的set和get方法. se ...

  5. angular基础入门

    第一章 AngularJs入门 AngularJS是一款由Google公司开发维护的前端框架,其克服了HTML在构建应用上的诸多不足,从而降低了开发成本提升了开发效率. 1 特点 AngularJS与 ...

  6. C# indexof 注意

  7. 【Vue+Node】解决axois请求数据跨域问题

    项目基于Vue前端+Node后台,启动两个服务,请求数据时,端口不一致造成跨域报错: (No 'Access-Control-Allow-Origin' header is present on th ...

  8. java操作Excel的poi基础语法

    创建一个简单的实列 package com.java.poi; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache ...

  9. VA Code编写html(1)

    <html> <head> <title>my webside</title> <!--win+‘/’注释行--> <!--防止中文乱 ...

  10. Kaggle竞赛顶尖选手经验汇总

    What is your first plan of action when working on a new competition? 理解竞赛,数据,评价标准. 建立交叉验证集. 制定.更新计划. ...