2491 玉蟾宫

2491 玉蟾宫

 

时间限制: 1 s
空间限制: 64000 KB
题目等级 : 大师 Master
 
 
 
题目描述 Description

  有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地。

  这片土地被分成N*M个格子,每个格子里写着'R'或者'F',R代表这块土地被赐予了rainbow,F代表这块土地被赐予了freda。
  现在freda要在这里卖萌。。。它要找一块矩形土地,要求这片土地都标着'F'并且面积最大。
  但是rainbow和freda的OI水平都弱爆了,找不出这块土地,而蓝兔也想看freda卖萌(她显然是不会编程的……),所以它们决定,如果你找到的土地面积为S,它们每人给你S两银子。

输入描述 Input Description

  第一行两个整数N,M,表示矩形土地有N行M列。
  接下来N行,每行M个用空格隔开的字符'F'或'R',描述了矩形土地。

输出描述 Output Description

  输出一个整数,表示你能得到多少银子,即(3*最大'F'矩形土地面积)的值。

样例输入 Sample Input

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

样例输出 Sample Output

45

数据范围及提示 Data Size & Hint

  对于50%的数据,1<=N,M<=200
  对于100%的数据,1<=N,M<=1000

 

来源:Nescafe 20

 1 #include<cmath>
 2 #include<cstdio>
 3 #include<iostream>
 4 using namespace std;
 5 int a[10000][10000];
 6 int leftt[10000],rightt[10000],h[10000]; 
 7 int ans;
 8 int main()
 9 {
10     int n,m;
11     cin>>n>>m;
12     for(int i=1;i<=n;i++)
13      {
14          for(int j=1;j<=m;j++)
15           {
16               char s;
17               cin>>s;
18               if(s=='R')
19                {
20                    a[i][j]=1;
21                }
22                else a[i][j]=0;
23           }
24      }
25      for(int i=1;i<=m;i++)
26       {
27           leftt[i]=1;
28           rightt[i]=m;
29       }
30      
31       for(int i=1;i<=n;i++)
32        {
33            int l=0;
34            int r=m+1;
35           for(int j=1;j<=m;j++)
36             {
37                 if(a[i][j]==1)
38                  {
39                      h[j]=0;
40                      l=j;
41                      leftt[j]=1;
42                  }
43                  else {
44                      h[j]++;
45                      leftt[j]=max(leftt[j],l+1);
46                  }
47             }
48         for(int j=m;j>=1;j--)
49          {
50              if(a[i][j]==1)
51               {
52                   r=j;
53                   rightt[j]=m;
54               }
55               else
56               {
57                   rightt[j]=min(rightt[j],r-1);
58                   }
59                   ans=max(ans,(rightt[j]-leftt[j]+1)*h[j]);
60               
61          }
62        }
63        cout<<ans*3;
64 }

 

posted @ 2017-04-20 17:24  ioioioioioio  阅读(110)  评论(0编辑  收藏  举报