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;
    }

  • 相关阅读:
    射频系统架构
    Tensorflow 2.0 mnist
    Lintcode 32. 最小子串覆盖 && Leetcode 76. Minimum Window Substring
    内存管理之智能指针unique_ptr&weak_ptr
    内存管理之智能指针shared_ptr
    内存管理之直接内存管理
    c++ 三大特性之继承
    稀疏矩阵乘法
    Linux环境下mysql常用命令
    字符串的查找删除
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351045.html
Copyright © 2011-2022 走看看