문제 링크입니다: https://www.acmicpc.net/problem/2160
2160번: 그림 비교
N(2≤N≤50)개의 그림이 있다. 각각의 그림은 5×7의 크기이고, 두 가지 색으로 되어 있다. 이때 두 가지의 색을 각각 ‘X’와 ‘.’으로 표현하기로 하자. 이러한 그림들이 주어졌을 때, 가장 비슷��
www.acmicpc.net
간단한 시뮬레이션 문제였습니다.
그림을 입력받는 과정에서 산수 실수를 해서 아쉽게도 한번 틀렸지만 대부분의 사람들은 한번에 AC를 받았을 것이라고 생각합니다.
This file contains hidden or 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 <string> | |
#include <algorithm> | |
using namespace std; | |
const int INF = 987654321; | |
const int MAX = 50 + 1; | |
const int ROW = 5; | |
const int COL = 7; | |
char paintings[MAX][ROW][COL]; | |
int cmp(int a, int b) | |
{ | |
int cnt = 0; | |
for (int i = 0; i < ROW; i++) | |
{ | |
for (int j = 0; j < COL; j++) | |
{ | |
if (paintings[a][i][j] != paintings[b][i][j]) | |
{ | |
cnt++; | |
} | |
} | |
} | |
return cnt; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
int row = 0; | |
for (int i = 1; i <= N * ROW; i++) | |
{ | |
string s; | |
cin >> s; | |
for (int j = 0; j < COL; j++) | |
{ | |
paintings[(i - 1) / ROW + 1][row][j] = s[j]; | |
} | |
row = i % ROW ? row + 1 : 0; | |
} | |
int cnt = INF; | |
pair<int, int> result; | |
for (int i = 1; i <= N - 1; i++) | |
{ | |
for (int j = i + 1; j <= N; j++) | |
{ | |
int tempCnt = cmp(i, j); | |
if (cnt < tempCnt) | |
{ | |
continue; | |
} | |
cnt = tempCnt; | |
result = { i, j }; | |
} | |
} | |
cout << result.first << " " << result.second << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2019
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 11376번 열혈강호 2 (0) | 2020.08.23 |
---|---|
백준 1052번 물병 (4) | 2020.08.21 |
백준 1953번 팀배분 (0) | 2020.08.02 |
백준 10090번 Counting Inversion (0) | 2020.07.26 |
백준 1264번 모음의 개수 (0) | 2020.07.19 |