Thứ Tư, 27 tháng 4, 2022

PV C++

#include <bits/stdc++.h>

using namespace std;

int n, m, g = 0;
int a[105][105] = {0};
int p[100005];

void nhap(){
    scanf("%d%d", &m, &n);
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
    }
}

bool check(int x, int y){
    if (x < y) return true;
    else return false;
}

void xuly(){
     for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[i-1][j] == 0 && a[i][j-1] == 0 && a[i][j] == 1){
                int dong = 1, cot = 1;
                while(a[i+dong][j] != 0){
                    dong++;
                }
                while(a[i][j+cot] != 0){
                    cot++;
                }
                g++; p[g] = dong*cot;
            }
        }
    }   
    sort(p+1, p+1+g, check);
    for (int i = 1; i <= g; i++){
        cout << p[i] << endl;
    }
}

int main(){
    freopen("PV.INP", "r", stdin);
    freopen("PV.OUT", "w", stdout);
    nhap();
    xuly();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.