KDHzoot's Github

Code for study, project, etc

자세히보기

알고리즘/PS

[백준 14654] 스테판 쿼리

kdhzoot 2018. 5. 21. 17:32

처음에 문제를 잘못 이해해서 이긴 사람은 자신이 낸 패를 그대로 계속 내는 문제인 줄 알았다.

그래서 코드를 필요한 부분만 수정하느라 지저분해졌다.

가위바위보의 승패를 쉽게 판단하기 위해 게임의 결과가 같으면 두 손패를 뺀 뒤 3으로 나눈 나머지가 같음을 이용했다.


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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#define mod 1000000009
using namespace std;
 
int arr[305];
int brr[305];
 
int main(void) {
    int n, ans = 1, cnt = 0;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> brr[i];
    }
 
    int prev = 0;
    
    for(int i=0;i<n;i++){
        if (arr[i] == brr[i]) {
            prev *= -1;
            cnt = 1;
            continue;
        }
 
        int gd = 3 + arr[i] - brr[i];
 
        if (gd % 3 == 1) {    //1이 우승
            if (prev == 1) {
                cnt++;
                ans = ans > cnt ? ans : cnt;
            }
            else {
                prev = 1;
                cnt = 1;
            }
        }
        else if (gd % 3 == 2) {    //-1이 우승
            if(prev == -1) {
                cnt++;
                ans = ans > cnt ? ans : cnt;
            }
            else {
                prev = -1;
                cnt = 1;
            }
        }
    }
 
    cout << ans << endl;
}
cs