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;
}

最新文章

  1. swt shell设置窗口位于屏幕中间
  2. 【转】查询oracle比较慢的session和sql
  3. [求助] win7 x64 封装 出现 Administrator.xxxxx 的问题
  4. HDOJ三部曲-DP-1017-pearls
  5. Pongo建立信号基站-实际上还是考中位数
  6. [DP] LCS小结
  7. IIS7 URL Rewrite 用法实例
  8. JSON序列化时消除空格
  9. VS快捷键失效问题
  10. Django之Django终端打印SQL语句
  11. 漏洞扫描工具Nessu的安装和简单使用
  12. SSE图像算法优化系列二十一:基于DCT变换图像去噪算法的进一步优化(100W像素30ms)。
  13. Python idle运行代码出现&#39;ascii&#39; codec can&#39;t encode characters in position 0-2
  14. 安装python包时报错
  15. 《区块链100问》第84集:资产代币化之对标黄金Digix
  16. MySQL year函数
  17. “全栈2019”Java第十四章:二进制、八进制、十六进制
  18. MyBatis动态SQL底层原理分析 与 JavaScript中的Date对象,以及UTC、GMT、时区的关系
  19. 数据结构之 图论---连通分量的个数(dfs搜索)
  20. 从缓冲上看阻塞与非阻塞socket在发送接收上的区别(转载)

热门文章

  1. [Swift]注册并购买加入Apple开发者计划。提示: “你的支付授权失败。请核对你的信息并重试,或尝试其他支付方式。请联系你的银行”
  2. Codeforces Round #198 (Div. 2)E题解
  3. 应用MVP模式对遗留代码进行重构
  4. Codeforces Round #447
  5. HTML实现图片360度循环旋转
  6. mybatis学习笔记之基础框架(2)
  7. UWP App Services in Windows 10
  8. Win10 BackgroundTask
  9. js 正则 测试
  10. day05_20190127_python之路——常用模块