문제 링크입니다: https://www.acmicpc.net/problem/12115
12115번: Baza
The first line of input contains N (1 ≤ N ≤ 103) and M (1 ≤ M ≤ 103), the size of the database. Each of the following N lines contains M numbers Aij (1 ≤ Aij ≤ 106), the content of the database. The following line contains Q (1 ≤ Q ≤ 50), the number of que
www.acmicpc.net
영어 문제라는 것만 제외하면 상당히 쉬운 문제였습니다.
-1에는 어떠한 숫자가 와도 되고 -1을 제외한 숫자들은 같은 위치에 있는 열들의 개수를 구하면 됐습니다.
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> | |
using namespace std; | |
const int MAX = 1000; | |
int N, M; | |
int arr[MAX][MAX]; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
cin >> N >> M; | |
for (int i = 0; i < N; i++) | |
for (int j = 0; j < M; j++) | |
cin >> arr[i][j]; | |
int Q; | |
cin >> Q; | |
for (int i = 0; i < Q; i++) | |
{ | |
vector<int> v(M); | |
for (int j = 0; j < M; j++) | |
cin >> v[j]; | |
int num = 0; | |
for (int j = 0; j < N; j++) | |
{ | |
bool flag = true; | |
for (int k = 0; k < M; k++) | |
{ | |
// -1은 아무 숫자나 와도 된다 | |
if (v[k] == -1) | |
continue; | |
// -1이 아닌 숫자는 다 같아야 한다. | |
if (v[k] != arr[j][k]) | |
{ | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
num++; | |
} | |
cout << num << "\n"; | |
} | |
return 0; | |
} |


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1238번 파티 (0) | 2019.05.22 |
---|---|
백준 12116번 Uzastopni (0) | 2019.05.15 |
백준 17144번 미세먼지 안녕! (5) | 2019.05.09 |
백준 17143번 낚시왕 (4) | 2019.05.09 |
백준 17142번 연구소 3 (3) | 2019.05.08 |