Ultraviolet A-10043 Chainsaw Massacre

Source: Internet
Author: User

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 cocould serve as the dance floor. the area inwhich you shoshould search is also rectangular and the dance floor mustbe entirely located in that area. its sides shoshould 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 bo Rders 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 lengthLAnd widthWOf 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, andXAndYProvide its coordinates in meters with respect to the upper leftcorner.
  • k x y dx dy, WhereK> 1 provides the number of trees in a line withcoordinates.
  • 0Denotes the end of the scenario.
The coordinates X, Y, DX, And DyAre 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
22 3010 102 1 1 8 02 1 9 8 00

Sample output
680

There are n trees on the plane, and a rectangle with the largest area is located.

Train of Thought: sort by Y coordinate and then scan. Each time you scan to a tree, you can know the distance between it and the previous tree. Then, you can update the statistics on the leftmost and rightmost sides of each X coordinate, calculate every time

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.