您的位置:首页 > 其它

LA 3029(悬线法)

2015-11-26 11:24 357 查看


City Game

Time Limit: 3000ms
Memory Limit: 131072KB

This problem will be judged on UVALive. Original ID: 3029

64-bit integer IO format: %lld      Java class name: Main

Prev Submit Status Statistics Discuss Next

Font Size: 
+
 
-

Type: 
None
Graph Theory
    2-SAT
    Articulation/Bridge/Biconnected Component
    Cycles/Topological Sorting/Strongly Connected Component
    Shortest Path
        Bellman Ford
        Dijkstra/Floyd Warshall
    Euler Trail/Circuit
    Heavy-Light Decomposition
    Minimum Spanning Tree
    Stable Marriage Problem
    Trees
    Directed Minimum Spanning Tree
    Flow/Matching
        Graph Matching
            Bipartite Matching
            Hopcroft–Karp Bipartite Matching
            Weighted Bipartite Matching/Hungarian Algorithm
        Flow
            Max Flow/Min Cut
            Min Cost Max Flow
DFS-like
    Backtracking with Pruning/Branch and Bound
    Basic Recursion
    IDA* Search
    Parsing/Grammar
    Breadth First Search/Depth First Search
    Advanced Search Techniques
        Binary Search/Bisection
        Ternary Search
Geometry
    Basic Geometry
    Computational Geometry
    Convex Hull
    Pick's Theorem
Game Theory
    Green Hackenbush/Colon Principle/Fusion Principle
    Nim
    Sprague-Grundy Number
Matrix
    Gaussian Elimination
    Matrix Exponentiation
Data Structures
    Basic Data Structures
    Binary Indexed Tree
    Binary Search Tree
    Hashing
    Orthogonal Range Search
    Range Minimum Query/Lowest Common Ancestor
    Segment Tree/Interval Tree
    Trie Tree
    Sorting
    Disjoint Set
String
    Aho Corasick
    Knuth-Morris-Pratt
    Suffix Array/Suffix Tree
Math
    Basic Math
    Big Integer Arithmetic
    Number Theory
        Chinese Remainder Theorem
        Extended Euclid
        Inclusion/Exclusion
        Modular Arithmetic
    Combinatorics
        Group Theory/Burnside's lemma
        Counting
    Probability/Expected Value
Others
    Tricky
    Hardest
    Unusual
    Brute Force
    Implementation
    Constructive Algorithms
    Two Pointer
    Bitmask
    Beginner
    Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
    Greedy
    Divide and Conquer
Dynamic Programming
 
 
Tag it!

[PDF Link]

Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees, factories and buildings. There is still some space in the area that is unoccupied.
The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in
each area. But he comes across some problems he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.

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

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


Input

The first line of the input file 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 two integers-area length M<=1000 and width N<=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 are:

R reserved unit

F free unit
In the end of each area description there is a separating line.


Output

For each data set in the input file print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in 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

Regionals 2004, Europe - Southeastern

Prev Submit Status Statistics Discuss Next

 题意是找一个最大的全由F组成的矩阵,输出面积乘3,单调递减栈左右扫一遍

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 10;
int a[maxn],s[maxn][maxn];
int main()
{
int T;scanf("%d",&T);
while(T--) {
int n,m;scanf("%d%d",&n,&m);
stack<int> Q;
memset(a,0,sizeof a);
int ans = 0;
for(int i = 1; i <= n; ++i) {
while(!Q.empty()) Q.pop();
Q.push(0);
a[0] = -1;
for(int j = 1; j <= m; ++j) {
++a[j];
char ch = getchar();
while(ch != 'R' && ch != 'F') ch = getchar();
s[i][m-j+1] = ch;
if(ch == 'R') a[j] = 0;
while(a[Q.top()] >= a[j]) Q.pop();
ans = max(ans,(j-Q.top())*a[j]);
Q.push(j);
}
}
memset(a,0,sizeof a);
for(int i = 1; i <= n; ++i) {
while(!Q.empty()) Q.pop();
Q.push(0);
a[0] = -1;
for(int j = 1; j <= m; ++j) {
++a[j];
char ch = s[i][j];
if(ch == 'R') a[j] = 0;
while(a[Q.top()] >= a[j]) Q.pop();
ans = max(ans,(j-Q.top())*a[j]);
Q.push(j);
}
}
printf("%d\n",ans*3);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  单调栈 悬线法