문제 링크입니다: https://www.acmicpc.net/problem/17829
17829번: 222-풀링
조기 졸업을 꿈꾸는 종욱이는 요즘 핫한 딥러닝을 공부하던 중, 이미지 처리에 흔히 쓰이는 합성곱 신경망(Convolutional Neural Network, CNN)의 풀링 연산에 영감을 받아 자신만의 풀링을 만들고 이를 222-풀링이라 부르기로 했다. 다음은 8×8 행렬이 주어졌다고 가정했을 때 222-풀링을 1회 적용하는 과정을 설명한 것이다 행렬을 2×2 정사각형으로 나눈다. 각 정사각형에서 2번째로 큰 수만 남긴다. 여기서 2번째로 큰 수란, 정사
www.acmicpc.net
단순 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
const int MAX = 1024; | |
int arr[MAX][MAX]; | |
int main(void) | |
{ | |
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 >> arr[i][j]; | |
} | |
} | |
while (N != 1) | |
{ | |
vector<vector<int>> temp(N/2, vector<int>(N/2, 0)); | |
for (int y = 0; y < N; y += 2) | |
{ | |
for (int x = 0; x < N; x += 2) | |
{ | |
int tempY = y; | |
int tempX = x; | |
vector<int> v(4); | |
v[0] = arr[tempY][tempX]; | |
v[1] = arr[tempY + 1][tempX]; | |
v[2] = arr[tempY][tempX + 1]; | |
v[3] = arr[tempY + 1][tempX + 1]; | |
sort(v.begin(), v.end()); | |
temp[y / 2][x / 2] = v[2]; | |
} | |
} | |
N /= 2; | |
for (int i = 0; i < N; i++) | |
{ | |
for (int j = 0; j < N; j++) | |
{ | |
arr[i][j] = temp[i][j]; | |
} | |
} | |
} | |
cout << arr[0][0] << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1041번 주사위 (2) | 2019.11.08 |
---|---|
백준 2812번 크게 만들기 (4) | 2019.11.08 |
백준 17828번 문자열 화폐 (0) | 2019.11.04 |
백준 17827번 달팽이 리스트 (0) | 2019.11.04 |
백준 17826번 나의 학점은? (0) | 2019.11.04 |