90分求助,#8过不去
查看原帖
90分求助,#8过不去
1290314
hdh1103楼主2024/3/8 17:36
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

// 0 1 6 ,1 0 6 ,1 6 0, 6 0 1, 6 1 0 ,0 6 1
//


int a[22][22];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int s = n*m;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            cin>>a[i][j];
        }
        }

    if(k==1){
        cout<<1;
        return 0;
    }
    //遍历每一个点
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            //选定(i,j)了,选定右下角的点
            for(int f = i;f<=n;f++){
                for(int h = j;h<=m;h++){
                    //统计1的个数
                    int count = 0;
                    //选定右下角的点为(f,h)
                    //三种情况,
                    //两个点在同一行
                    if(i==f){
                        //从这一点出发,列去改变。找1
                        for(int q = j;q<=h;q++){
                            if(a[i][q]==1) count++;
                        }
                    }
                    //两个点在同一列
                    else if(j==h){
                        for(int q=i;q<=f;q++){
                            if(a[q][j]==1) count++;
                        }
                    }

                    //两个点在不同列,不同行
                    else{
                        for(int q = i;q<=f;q++){
                            for(int p = j;p<=h;p++){
                                if(a[q][p]==1) count++;
                            }
                        }
                    }
                    //统计面积
                    if(count==k){
                        int c =(f-i+1)*(h-j+1);
                        if(c<s){
                            s=c;
                        }
                    }
                }
            }
        }
    }

    cout<<s;
    return 0;
}

2024/3/8 17:36
加载中...