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. JS轮播图动态渲染四种方法

    一. 获取轮播图数据  ajax 二.根据数据动态渲染 (根据当前设备 屏幕宽度判断) 1. 准备数据 2. 把数据转换成html格式的字符串 动态创建元素 字符串拼接 模板引擎 框架方法 2.把字符 ...

  2. Kaggle之泰坦尼克号幸存预测估计

    上次已经讲了怎么下载数据,这次就不说废话了,直接开始.首先导入相应的模块,然后检视一下数据情况.对数据有一个大致的了解之后,开始进行下一步操作. 一.分析数据 1.Survived 的情况 train ...

  3. 外观模式(Facade)C++实现

    外观模式 意图: 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一系统更加容易使用. 适用性: 1.在设计初期阶段,应该要有意识的将不同的两个层分离,比如经典的三层架 ...

  4. MVP演化论

    本文是翻译MVP: Model-View-Presenter The Taligent Programming Model for C++ and Java(Mike Potel)文章的摘要.该文介绍 ...

  5. 给<hr/>添加样式

    点线式 破折线式 直线式 双线式 脊线式 槽线式 内嵌效果的 突起效果的 border-top:10px 设置水平线的大小 <hr style=" border-top:5px dot ...

  6. (转)webpack从零开始第6课:在Vue开发中使用webpack

    vue官方已经写好一个vue-webpack模板vue_cli,原本自己写一个,发现官方写得已经够好了,自己写显得有点多余,但为了让大家熟悉webpack,决定还是一步一步从0开始写,但源文件就直接拷 ...

  7. APP开发中,如何从UI设计上提升APP用户体验

    设计中有很多细微的东西要注意,就如UI设计中,元素的统一性,图标风格.段落的排版等等,只有能注意这些细节,你的 APP UI 才算合格. 干货君总结了17个提升用户体验的 UI 设计小技巧,也是我们日 ...

  8. Django学习笔记----settings and database_based App demo

    原文参考docs.djangoproject.com, what can manage.py utility do? find here. 1.Database Setup 编辑settings.py ...

  9. 【Oracle】管理还原数据(undo)

    1. 查看undo相关参数 SYS@LGR> show parameter undo NAME TYPE VALUE ------------------------------------ - ...

  10. css3动画,点击圆形背景扩展整个页面效果

    上次做项目的时候,要求点击链接,这个链接的圆形背景扩散充满整个页面,今天把这个效果整理一下,是简单的css3的动画特效,粘贴下面的代码看效果 <!DOCTYPE html> <htm ...