본문 바로가기

USACO/Bronze

백준 5947 Book Club (USACO December 2010 Bronze 1번)

문제 링크: https://www.acmicpc.net/problem/5947

 

5947번: Book Club

Bessie is looking for cows to join her book club. While the herd has N (2 <= N <= 50,000) cows conveniently numbered 1..N, she wants only the most discerning and social cows for her book club. Thus, like a dating service, she has created a questionnaire an

www.acmicpc.net

주어진 조건 p개를 모두 만족하는 cow의 수를 세면 됨.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
 
int n, q, p, a[50001][51], check[50001];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n >> q >> p;
    for(int i = 1; i <= n; i++for(int j = 1; j <= q; j++)
        cin >> a[i][j];
 
    for(int i = 0; i < p; i++) {
        int qj, aj;
        cin >> qj >> aj;
        for(int j = 1; j <= n; j++) {
            if(a[j][qj] == aj)
                check[j]++;
        }
    }
 
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(check[i] == p)
            ans++;
    }
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter