【題解】ZeroJudge e798: p5. 卷積神經網路

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e798

#include <iostream>
#include <algorithm>
using namespace std;

int a[20][20];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            cin >> a[i][j];
        }
    }

    for (int i=0; i<N/2; i++){
        for (int j=0; j<N/2; j++){
            int mx = a[2*i][2*j];
            mx = max(mx, a[2*i][2*j+1]);
            mx = max(mx, a[2*i+1][2*j]);
            mx = max(mx, a[2*i+1][2*j+1]);
            cout << mx << ' ';
        }
        cout << '\n';
    }
    return 0;
}

Python code (credit: Amy Chou)

N = int(input())
a = []
for _ in range(N):
    a.append(list(map(int, input().split())))

for i in range(N//2):
    for j in range(N//2):
        tmp = [a[2*i][2*j], a[2*i][2*j+1], a[2*i+1][2*j], a[2*i+1][2*j+1]]
        print(max(tmp), ' ', sep='', end='')
    print()
分享本文 Share with friends