zoukankan      html  css  js  c++  java
  • UVA

    Description

    Download as PDF


     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 ($0<l,wleq 10000$,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 $(x,y),(x+dx,y+dy),ldots,(x+(k-1)dx,y+(k-1)dy)$.
    • 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 $[0,l]	imes[0,w]$.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
    ", ans);
    	}
    	return 0;
    }



  • 相关阅读:
    gns3 接口说明 转
    Java二进制指令代码解析
    java大神RednaxelaFX
    深入理解Java虚拟机
    java环境变量设置
    openjdk
    JAVA call graphs JAVA调用图
    Java虚拟机原理图解
    JAVA --BYTECODE
    利用hsdis和JITWatch查看分析HotSpot JIT compiler生成的汇编代码
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7010085.html
Copyright © 2011-2022 走看看