Uva1330 / poj1964 City Game

Posted 俺是小程

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Uva1330 / poj1964 City Game相关的知识,希望对你有一定的参考价值。

这里 是针对这道题比较详细的讲解。

文章中指出的子问题是有例题的,具体见这里

  1 #include <cstdio>
  2 #include <stack>
  3 #include <algorithm>
  4 #include <iostream>
  5 #include <cstring>
  6 using namespace std;
  7 const int MAXN = 1e3 + 20;
  8 
  9 bool S[MAXN][MAXN];
 10 int s[MAXN][MAXN];
 11 int N, M;
 12 
 13 struct rec // rectangle
 14 {
 15     int l, h;
 16     rec(int l = 0, int h = 0) : l(l), h(h) {}
 17 };
 18 struct _Stack
 19 {
 20     stack<rec> sta;
 21 
 22     inline void init()
 23     {
 24         while(!sta.empty())
 25             sta.pop();
 26     }
 27 
 28     inline int Pushin(rec now)
 29     {
 30         if(sta.empty() || sta.top().h < now.h)
 31         {
 32             sta.push(now);
 33             return 0;
 34         }
 35 
 36         rec cur;
 37         int len = 0, area = 0;
 38         while(!sta.empty() && now.h < sta.top().h)
 39         {
 40             cur = sta.top();
 41             len += cur.l;
 42             area = max(area, len * cur.h);
 43             sta.pop();
 44         }
 45         sta.push(rec(len + now.l, now.h));
 46         return area;
 47     }
 48 }Stack;
 49 
 50 inline void init()
 51 {
 52     memset(S, false, sizeof(S));
 53     memset(s, 0, sizeof(s));
 54     Stack.init();
 55 }
 56 
 57 inline void solve()
 58 {
 59     char ch;
 60     for(int i = 1; i <= N; i++)
 61         for(int j = 1; j <= M; j++)
 62         {
 63             cin>>ch;
 64             if(ch == \'F\') S[i][j] = true;
 65             else S[i][j] = false;
 66         }
 67 
 68     for(int i = 1; i <= N; i++)
 69         for(int j = 1; j <= M; j++)
 70             S[i][j] == true ? s[i][j] = s[i - 1][j] + 1 : s[i][j] = 0;
 71         
 72     /*for(int i = 1; i <= N; i++)
 73         {
 74             for(int j = 1; j <= M; j++)
 75                 cout<<s[i][j]<<" ";
 76             cout<<endl;
 77         }*/
 78     int area = 0;
 79     for(int i = 1; i <= N; i++)
 80     {
 81         for(int j = 1; j <= M; j++)
 82             area = max(area, Stack.Pushin(rec(1, s[i][j])));
 83 
 84         area = max(area, Stack.Pushin(rec(1, 0)));
 85         Stack.init();
 86     }    
 87 
 88     cout<<area * 3<<endl;
 89 }
 90 
 91 int main()
 92 {
 93     //freopen("1330.txt", "r", stdin);
 94     ios::sync_with_stdio(false);
 95     int K;
 96     cin>>K;
 97     while(K--)
 98     {
 99         cin>>N>>M;
100         init();
101         solve();
102     }
103     return 0;
104 }

 

以上是关于Uva1330 / poj1964 City Game的主要内容,如果未能解决你的问题,请参考以下文章

UVA1330 City Game

POJ1964-City Game

poj 1330(初探LCA)

POJ1330(LCA入门题)

POJ 1330 Nearest Common Ancestors(lca)

Poj 1330Nearest Common Ancestors