zoukankan      html  css  js  c++  java
  • HDOJ 2870 Largest Submatrix

    逐层的找最大面积。

    Largest Submatrix

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 967    Accepted Submission(s): 467


    Problem Description
    Now here is a matrix with letter 'a','b','c','w','x','y','z' and you can change 'w' to 'a' or 'b', change 'x' to 'b' or 'c', change 'y' to 'a' or 'c', and change 'z' to 'a', 'b' or 'c'. After you changed it, what's the largest submatrix with the same letters you can make?
     

    Input
    The input contains multiple test cases. Each test case begins with m and n (1 ≤ m, n ≤ 1000) on line. Then come the elements of a matrix in row-major order on m lines each with n letters. The input ends once EOF is met.
     

    Output
    For each test case, output one line containing the number of elements of the largest submatrix of all same letters.
     

    Sample Input
    2 4
    abcw
    wxyz
     

    Sample Output
    3
     

    Source
     

    Recommend
    gaojie
     

    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    const int N=1005;

    char a[N][N];
    int high[N];
    int C,R;

    bool isH(char stc,char c)
    {
        if(stc=='a')
            return c=='a'||c=='w'||c=='y'||c=='z';
        if(stc=='b')
            return c=='b'||c=='w'||c=='x'||c=='z';
        if(stc=='c')
            return c=='c'||c=='x'||c=='y'||c=='z';
        return false;
    }

    int main()
    {
        while(scanf("%d%d",&R,&C)!=EOF)
        {
            for(int i=0;i<R;i++)
              scanf("%s",a);

        int ans=-1;

        for(char stc='a';stc<='c';stc++)
        {
            memset(high,0,sizeof(high));

            for(int i=0;i<R;i++)
            {
                for(int j=0;j<C;j++)
                {
                    if(isH(stc,a[j]))
                        high[j]++;
                    else
                        high[j]=0;
                }

                for(int j=0;j<C;j++)
                {
                    int cnt=1;
                    if(high[j]==0) continue;
                    for(int k=j-1;k>=0&&high[k]>=high[j];k--)
                        cnt++;
                    for(int k=j+1;k<C&&high[k]>=high[j];k++)
                        cnt++;
                    ans=max(ans,high[j]*cnt);
                }
            }
        }

        printf("%d\n",ans);

        }

        return 0;
    }

  • 相关阅读:
    js如何获取当天日期的开始时间和结束时间
    bootstrapTable 刷新数据
    vue全家桶
    JavaScript数组是否存在及是否存在某个元素
    asp.net core 负载均衡集群搭建(centos7+nginx+supervisor+kestrel)
    (转) 将ASP.NET Core应用程序部署至生产环境中(CentOS7)
    mysql 5.7 docker 主从复制架构搭建
    CentOS6.x生产环境下一键安装mono+jexus的脚本,自启动,带服务,版本号自控
    使用 Json.Net 对Json文本进行 增删改查
    C# dynamic 动态创建 json
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351046.html
Copyright © 2011-2022 走看看