zoukankan      html  css  js  c++  java
  • UVA

    Input
    The rst line of the input le contains an integer K | determining the number of datasets. Next lines
    contain the area descriptions. One description is de ned in the following way: The rst line contains
    two integers-area length M ≤ 1000 and width N ≤ 1000, separated by a blank space. The next M
    lines contain N symbols that mark the reserved or free grid units, separated by a blank space. The
    symbols used are:
    R - reserved unit
    F - free unit
    In the end of each area description there is a separating line.
    Output
    For each data set in the input le print on a separate line, on the standard output, the integer that
    represents the pro t obtained by erecting the largest building in the area encoded by the data set.
    Sample Input
    2
    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
    5 5
    R R R R R
    R R R R R
    R R R R R
    R R R R R
    R R R R R
    Sample Output
    45
    0

    1.如何拆分最大矩形,遍历所有点的上左右边界,在遍历中求最大值

    2.颠倒看数组都是一样的

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    
    #define MAX 1000
    
    using namespace std;
    int A[MAX][MAX], up[MAX][MAX], l[MAX][MAX], r[MAX][MAX], m, n, T;
    
    int main() {
        cin >> T;
        while (T--) {
            cin >> m >> n;
            for (int i = 0, c; i < m; ++i) {
                for (int j = 0; j < n; ++j) {
                    do { c = getchar(); }
                    while (c != 'F' && c != 'R');
                    A[i][j] = c == 'F';
                }
            }
            int ans = 0;
            for (int i = 0; i < m; ++i) {
                for (int j = 0, lo = 0; j < n; ++j) {
                    if (!A[i][j]) {
                        up[i][j] = l[i][j] = 0; //把l设到最左,方便上方的点求lo
                        lo = j + 1;
                    } else {
                        up[i][j] = i == 0 ? 1 : up[i - 1][j] + 1;
                        l[i][j] = i == 0 ? lo : max(l[i - 1][j], lo);
                    }
                }
    
                for (int j = n - 1, ro = n; j >= 0; --j) {
                    if (!A[i][j]) {
                        r[i][j] = n, ro = j;
                    } else {
                        r[i][j] = i == 0 ? ro : min(r[i - 1][j], ro);
                        ans = max(ans, up[i][j] * (r[i][j] - l[i][j])); //在求右边界时同时求矩形面积最大值
                    }
                }
            }
            cout << ans * 3 << endl;
        }
    }
  • 相关阅读:
    拾遗:systemctl --user
    拾遗:~/.zshrc 配置
    拾遗:YouCompleteMe 前传——编译安装 llvm + clang
    洛谷P1546 最短网络 Agri-Net(最小生成树,Kruskal)
    洛谷P1462 通往奥格瑞玛的道路(二分+spfa,二分+Dijkstra)
    HDU6669 Game(思维,贪心)
    HDU6672 Seq(找规律)
    HDU6668 Polynomial(模拟)
    洛谷P1378 油滴扩展(搜索)
    机器学习数学基础(四)
  • 原文地址:https://www.cnblogs.com/wangsong/p/7670425.html
Copyright © 2011-2022 走看看