HDU 1505 City Game

来源:互联网 发布:一骑当千镜头数据 编辑:程序博客网 时间:2024/05/02 04:29

自己学的太死了。 也用不上刚学的。


这个题就是 对于一行来说 每一个位置 向上看 都有一个最大的连续的空地个数。 


那么 求出这一行  的每一个位置的最大连续空地个数。 这个题也就做出来了。  同 HDU 1506. 思路是一样的了。


#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <algorithm>#include <fstream>#include <set>#include <map>#include <queue>#include <stack>#include <list>#include <vector>#include <cmath>#include <iomanip>typedef long long LL;typedef unsigned long long LLU;const double PI=acos(-1.0);using namespace std;#define MAXN 1000+10int v[MAXN][MAXN] = {0};int main (){    int n;    scanf("%d",&n);    while(n--){        int m,n;        scanf("%d%d",&m,&n);        memset(v,0,sizeof(v));        for(int i = 1; i <= m; i++){            for(int j = 1; j <= n; j++){                char s[10];                scanf("%s",s);                if(s[0] == 'F') v[i][j] = v[i-1][j] + 1;                else v[i][j] = 0;            }        }        int M = 0;        for(int i = 1; i <= m; i++){            int l[MAXN] = {0},r[MAXN] = {0};            v[i][n+1] = -1;            v[i][0] = -1;            for(int j = 1; j <= n; j++)                l[j] = j,r[j] = j;            for(int j = 1; j <= n; j++)                while(v[i][l[j]-1] >= v[i][j])                    l[j] = l[l[j]-1];            for(int j = n; j >= 1; j--)                while(v[i][r[j]+1] >= v[i][j])                    r[j]=r[r[j]+1];            for(int j = 1; j <= n; j++)                M = max(M, v[i][j]*(r[j]-l[j]+1));        }        printf("%d\n",M*3);    }    return 0;}


0 0