hdu1505---City Game (monotone stack)

Source: Internet
Author: User

Problem Description
Bob is a strategy game programming specialist. In He new city building game the gaming environment was as Follows:a City was built up by areas, in which there was street S, trees,factories and buildings. There is still some space in the area it is unoccupied. The strategic task of his game was to win as much rent money from these free spaces. To win rent-must erect buildings, that can is only being rectangular, as long and wide as you can. Bob is trying to find a by-build the biggest possible building in each area. But he comes across some problems–he isn't allowed to destroy already existing buildings, trees, factories and streets In the area he's building in.

Each of the area have its width and length. The area was divided into a grid of equal square units. The rent paid for each unit on which you ' re building stands are 3$.

Your task is to help Bob solve this problem. The whole city was divided into K areas. Each one of the areas is rectangular and have a different grid size with its own length M and width n.the existing occupied Units is marked with the symbol R. The unoccupied units is marked with the symbol F.

Input
The first line of the input contains an integer k–determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way:the first line contains both Integers-area length m<=1000 and width n&l t;=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used is:

r–reserved Unit

F–free Unit

The end of each area description there are a separating line.

Output
For each data set with the input print on a separate line, on the standard output, the integer that represents the profit OB tained by erecting the largest building, the area encoded by the data set.

Sample Input

2
5 6
R F F f f f
F F f f f f
R-R R F F F
F F f f f f
F F f f f f

5 5
R R-R r R
R R-R r R
R R-R r R
R R-R r R
R R-R r R

Sample Output

45
0

Source
Southeastern Europe 2004

The monotone stack casually, the pieces held, and then left to right expansion

/************************************************************************* > File Name:hdu1505.cpp > Auth Or:alex > Mail: [email protected] > Created time:2015 May 10 Sunday 21:43 44 seconds ******************************** ****************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Static Const intN = .;CharMat[n][n];Charstr[Ten];intHeight[n][n]; PLL Stack[n];intTop;intL[n];intR[n];intUse[n][n];intMain () {intN, M;intTscanf("%d", &t); while(t--) {scanf("%d%d", &n, &m); for(inti =1; I <= N; ++i) { for(intj =1; J <= M; ++J) {scanf('%s ', str); MAT[I][J] = str[0]; }        } for(inti =1; I <= m; ++i) {height[i][0] =0; for(intj =1; J <= N; ++J) {Height[i][j] = height[i][j-1];if(Mat[j][i] = =' F ') {++height[i][j]; }Else{Height[i][j] =0; }            }        }memset(Use,0,sizeof(use));intAns =0; for(inti =1; I <= N; ++i) {Top =0; for(intj = m; J >=1; --J) {if(!                TOP) {Stack[++top] = Make_pair (Height[j][i], J); }Else{ while(TOP) {PLL u = stack[top];if(U.first <= Height[j][i]) { Break; } L[u.second] = j +1;                    --top;                } Stack[++top] = Make_pair (Height[j][i], J); }            } while(TOP)                {PLL u = stack[top];                --top; L[u.second] =1; } for(intj =1; J <= M; ++J) {if(!                TOP) {Stack[++top] = Make_pair (Height[j][i], J); }Else{ while(TOP) {PLL u = stack[top];if(U.first <= Height[j][i]) { Break; } R[u.second] = J-1;                    --top;                } Stack[++top] = Make_pair (Height[j][i], J); }            } while(TOP)                {PLL u = stack[top];                --top;            R[u.second] = m; } for(intj =1; J <= M; ++J) {intL = l[j];intr = R[j]; ans = max (ans, (r-l +1) * Height[j][i]); }        }printf("%d\n", ans *3); }return 0;}

hdu1505---City Game (monotone stack)

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.