zoukankan      html  css  js  c++  java
  • HDOJ 2830 Matrix Swapping II


    每一行判断高度,然后排序,枚举计算最大面积

    Matrix Swapping II

    Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 896    Accepted Submission(s): 597


    Problem Description
    Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries are all 1, and we define the maximum area of such rectangle as this matrix’s goodness. 

    We can swap any two columns any times, and we are to make the goodness of the matrix as large as possible.
     

    Input
    There are several test cases in the input. The first line of each test case contains two integers N and M (1 ≤ N,M ≤ 1000). Then N lines follow, each contains M numbers (0 or 1), indicating the N * M matrix
     

    Output
    Output one line for each test case, indicating the maximum possible goodness.
     

    Sample Input
    3 4
    1011
    1001
    0001
    3 4
    1010
    1001
    0001
     

    Sample Output
    4
    2
    Note: Huge Input, scanf() is recommended.
     

    Source
     

    Recommend
    gaojie
     


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

    using namespace std;

    const int N=1005;
    struct m
    {
    char a[N][N];
    int high[N];
    }G;

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

        for(int i=0;i<R;i++)
        {
            memset(G.high,0,sizeof(G.high));
            for(int j=0;j<C;j++)
            {
                for(int k=i;k>=0;k--)
                {
                    if(G.a[k][j]=='1')
                    G.high[j]++;
                    else break;
                }
            }

            sort(G.high,G.high+C);
    /*

            cout<<i<<":"<<endl;
            for(int j=0;j<C;j++)
                cout<<G.high[j]<<" ";
            cout<<endl;

    */
            for(int i=0;i<C;i++)
            {
                int cnt=C-i;
     //           cout<<cnt<<"*"<<G.high<<endl;
                ans=max(ans,cnt*G.high);
            }
        }

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

        return 0;
    }

  • 相关阅读:
    位运算一些简单的应用
    运算符的优先级
    Vue.js 指南-基础
    Nginx将项目配置在子目录
    JavaScript创建读取cookie代码示例【附:跨域cookie解决办法】
    JavaScript动态加载资源【js|css】示例代码
    Uploadifive 使用教程【结合七牛】
    mac 配置快捷键快速锁屏
    七牛大文件上传同步工具配置
    使用七牛云存储作为图床
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351045.html
Copyright © 2011-2022 走看看