当前位置: 代码迷 >> 综合 >> LA 3029 City Game
  详细解决方案

LA 3029 City Game

热度:92   发布时间:2023-12-06 08:35:13.0

题目:City Game


思路:扫描线


代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
using namespace std;#define maxn 1000int n,m;bool a[maxn+5][maxn+5];
int up[maxn+5][maxn+5]={0},Left[maxn+5][maxn+5]={0},Right[maxn+5][maxn+5]={0};int main() {int T;scanf("%d",&T);while(T--){scanf("%d%d",&m,&n);for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){char x;while(scanf("%c",&x)&&x!='R'&&x!='F');if(x=='R') a[i][j]=1;else a[i][j]=0;}}int ans=0;for(int i=1;i<=m;i++){int l=0,r=n+1;for(int j=1;j<=n;j++){if(a[i][j]) {l=j;Left[i][j]=1;up[i][j]=0;} else {up[i][j]=up[i-1][j]+1;if(i==1) Left[i][j]=l+1;else Left[i][j]=max(Left[i-1][j],l+1);}}for(int j=n;j>=1;j--){if(a[i][j]){r=j;Right[i][j]=n;} else {if(i==1) Right[i][j]=r-1;else Right[i][j]=min(Right[i-1][j],r-1);ans=max(ans,up[i][j]*(Right[i][j]-Left[i][j]+1));}}}printf("%d\n",ans*3);}return 0;
}


  相关解决方案