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

时间: 2024-08-08 11:24:16

UVA - 10043 Chainsaw Massacre的相关文章

计划,,留

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 一.<算法竞赛入门经典> 刘汝佳 (UVaOJ 351道题) 以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html "AOAPC I"

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

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发.   一.UVaOJ http://uva.onlinejudge.org  西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ.   二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html   "AO

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

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html “AOAPC I”是刘汝佳(大

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B