码迷,mamicode.com
首页 > 其他好文 > 详细

城市游戏

时间:2020-03-15 10:10:16      阅读:50      评论:0      收藏:0      [点我收藏+]

标签:高度   c++   ++   时间   i++   cout   long   size   main   

# 题意
n*m矩阵,每个点元素为R或F,求面积s最大的全部为F的字矩阵,输出3*s

# 题解
枚举每一行上每一列的点上的F高度,面积求法同直方图中的最大矩形,时间复杂度为O(nm)
小区别是当前行中当前列没有F即高度为0,不会对后面产生影响因为是断开的

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N=1010;
 5 bool a[N][N];
 6 int n,m;
 7 int stk[N],top;
 8 int h[N],wid[N];
 9 int ddz(int k){
10    int res = 0;
11    top = 0;
12    for(int i = 1; i <= m; i++)
13       if(a[k][i]) h[i]++;
14       else h[i] = 0;
15 
16    for(int i = 1; i <= m + 1; i++){
17       if(stk[top] < h[i]){
18          stk[++top] = h[i];
19          wid[top] = 1;
20          res = max(res,h[i]);
21       }
22       else{
23          int w=0;
24          while(top && stk[top] >= h[i]){
25             w += wid[top];
26             res = max(res,stk[top--] * w);
27          }
28          stk[++top] = h[i];
29          wid[top] = w+1;
30          res = max(res,stk[top] * wid[top]);
31       }
32    }
33    return res;
34 }
35 int main(){
36    ios::sync_with_stdio(0);
37    cin.tie(0);
38    cout.tie(0);
39    cin >> n >> m;
40    for(int i = 1; i <= n; i++)
41       for(int j = 1; j <= m; j++){
42          char c;
43          cin>>c;
44          a[i][j] = (c == F ? 1 : 0);
45       }
46    int ans=0;
47    for(int i = 1; i <= n; i++)
48       ans = max(ans,ddz(i));
49    cout << ans*3 << endl;
50 }

 

 

 

城市游戏

标签:高度   c++   ++   时间   i++   cout   long   size   main   

原文地址:https://www.cnblogs.com/hhyx/p/12495705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!