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;
        }
    }
  • 相关阅读:
    大数据总结
    spark_streaming_微批量处理
    spark_sql_解析器
    spark_sql_函数
    spark-sql-04-spark连接hive的几种方式
    spark-sql-04-on_hive
    spark-sql-04-hive
    CF550C Divisibility by Eight
    CF489C Given Length and Sum of Digits...
    CF550A Two Substrings
  • 原文地址:https://www.cnblogs.com/wangsong/p/7670425.html
Copyright © 2011-2022 走看看