zoukankan      html  css  js  c++  java
  • HDU1505 City Game 动态规划

    http://acm.hdu.edu.cn/showproblem.php?pid=1505

    自己写的屌丝代码:

    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #define MAXN 1050
    using namespace std;
    
    int N, M, u[MAXN][MAXN], l[MAXN][MAXN], G[MAXN][MAXN];
    
    inline int max(int x, int y)
    {
        return x > y ? x : y;
    }
    
    inline int min(int x, int y)
    {
        return x < y ? x : y;
    }
    
    int DP()
    {
        int Max = 0;
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                if (G[i][j]) {
                    int L = 1, H = 1, bx, by;
                    by = u[i][j] = u[i-1][j] + 1;
                    bx = l[i][j] = l[i][j-1] + 1;
                    Max = max(Max, max(bx*H, by*L)); 
                    for (int f = i-1; f > 0; --f) { 
                        
                        if (G[f][j]) {
                            ++H;
                            bx = min(bx, l[f][j]);
                        }
                        else {
                            break;
                        }
                        Max = max(Max, max(bx*H, by*L)); 
                    } 
                    for (int g = j-1; g > 0; --g) { 
                        
                        if (G[i][g]) {
                            ++L;
                            by = min(by, u[i][g]);
                        }
                        else {
                            break;
                        }
                        Max = max(Max, max(bx*H, by*L));
                    }
                }
                else {
                    u[i][j] = 0;
                    l[i][j] = 0;
                }
            }
        }
        return Max;
    }
    
    int main()
    {
        int T;
        char logo[4];
        scanf("%d", &T);
        while (T--) {
            scanf("%d %d", &N, &M);
            for (int i = 1; i <= N; ++i) {
                for (int j = 1; j <= M; ++j) {
                   scanf("%s", logo);
                   G[i][j] = (logo[0]== 'F');
                }
            }
            printf("%d\n", 3 * DP());
        }   
        return 0;
    }

    用1506的写法

    #include<stdio.h>
    #include<string.h>
    #define M 1005
    int a[M][M], l[M], r[M];
    
    int main() {
        int t, i, j, res, ans, n, m;
        char str[10];
        scanf("%d", &t);
        while (t-- && scanf("%d %d", &n, &m)) {
            memset(a[0], 0, sizeof (a[0]));
            for (i = 1; i <= n; i++)
                for (j = 1; j <= m; j++) {
                    scanf("%s", str);
                    if (str[0] == 'F')a[i][j] = a[i - 1][j] + 1;
                    else a[i][j] = 0;
                }
            ans = -1;
            for (i = 1; i <= n; i++) {
                for (j = 1; j <= m; j++)l[j] = r[j] = j;
                a[i][0] = a[i][m + 1] = -1;
                for (j = 2; j <= m; j++) {
                    while (a[i][j] <= a[i][l[j] - 1])
                        l[j] = l[l[j] - 1];
                }
                for (j = m - 1; j >= 1; j--) {
                    while (a[i][j] <= a[i][r[j] + 1])
                        r[j] = r[r[j] + 1];
                }
                for (j = 1; j <= m; j++) {
                    res = a[i][j]*(r[j] - l[j] + 1);
                    if (res > ans)ans = res;
                }
            }
            printf("%d\n", ans * 3);
        }
        return 0;
    }
  • 相关阅读:
    HttpRunner学习3--extract提取数据和引用
    利用Fiddler对Jmeter的请求进行抓包
    HttpRunner学习2--用例格式和简单使用
    HttpRunner学习1--Windows&Linux安装httprunner
    Linux日志中如何查找关键字及其前后的信息
    Linux命令学习-cat命令
    Linux下安装MySQL 5.7
    阿里云服务器修改主机名
    Linux下设置mysql允许远程连接
    利用PyInstaller打包exe文件
  • 原文地址:https://www.cnblogs.com/Lyush/p/2455531.html
Copyright © 2011-2022 走看看