zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    jQuery入门(8):工具
    jQuery入门(2):核心(核心函数,对象访问,多库共存)
    jQuery入门(6):Ajax
    jQuery入门(7):效果
    jQuery入门(4):CSS相关API
    threadwait/sleep
    【转】Query的extend扩展方法使用点滴
    jquery.query2.1.7.js 操作url
    zhuan
    通用分页存储过程 采用ROW_NUMBER(),支持2005及以后的版本
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/8973544.html
Copyright © 2011-2022 走看看