본문 바로가기

USACO/Bronze

백준 17027 Shell Game (USACO January 2019 Bronze 1번)

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

 

17027번: Shell Game

The first line of the input file contains an integer $N$ giving the number of swaps ($1 \leq N \leq 100$). Each of the next $N$ lines describes a step of the game and contains three integers $a$, $b$, and $g$, indicating that shells $a$ and $b$ were swappe

www.acmicpc.net

처음에 pebble이 1번에 있을때, 2번에 있을때, 3번에 있을때 각각의 상황에 따라 맞은 guess의 갯수들중 최대값을 구하면 됨.

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
32
33
#include <bits/stdc++.h>
using namespace std;
 
int n, a[101], b[101], g[101];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> g[i];
        a[i]--;
        b[i]--;
        g[i]--;
    }
 
    int ans = 0;
    for(int i = 0; i < 3; i++) {
        int shell[3= {};
        int cnt = 0;
        shell[i] = 1;
        for(int j = 0; j < n; j++) {
            swap(shell[a[j]], shell[b[j]]);
            if(shell[g[j]]) cnt++;
        }
        ans = max(ans, cnt);
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter