-
[14456] Hoof, Paper, Scissors (Bronze)BOJ 2021. 10. 8. 01:01
https://www.acmicpc.net/problem/14456
14456번: Hoof, Paper, Scissors (Bronze)
You have probably heard of the game "Rock, Paper, Scissors". The cows like to play a similar game they call "Hoof, Paper, Scissors". The rules of "Hoof, Paper, Scissors" are simple. Two cows play against each-other. They both count to three and then each s
www.acmicpc.net
<문제>
1을 기준으로 보면, 1이 이길수 있는 상대가 2가 될수도 있고, 3이될수도 있다.
전자일때 2는 1에게 지는 대신 3에게 이겨야 하고, 3은 2에게 지는대신 1에게 이기게된다.
처음에 기준을 1로 잡고, 이후 기준을 2 혹은 3으로 변경하며
각 인원이 1번의 승리와 1번의 패배로 이루어진 단방향 사이클을 떠올릴 수 있다.
1>2>3>1
1>3>2>1
결국 두가지 경우의수밖에 존재하지 않는 셈이고
각 경우의 수에서 누가 이기느냐에 의해서 또다시 3가지의 경우의 수로 나뉜다.
이는 전부 or로 묶어주고, 모든 로그를 2번에 걸쳐O(N) + O(N)으로 순회하며 답을 업데이트하면 된다.
<소스코드>
123456789101112131415161718192021222324252627282930313233#include <bits/stdc++.h>using namespace std;int n;int main(void) {int i;cin >> n;vector<pair<int, int>> v;for (i = 0; i < n; i++) {int x, y;cin >> x >> y;v.push_back({x, y});}int cnt = 0, ans = 0;for (i = 0; i < n; i++) {if (v[i].first == 1 && v[i].second == 2 ||v[i].first == 2 && v[i].second == 3 ||v[i].first == 3 && v[i].second == 1)cnt++;}ans = max(cnt, ans);cnt = 0;for (i = 0; i < n; i++) {if (v[i].first == 1 && v[i].second == 3 ||v[i].first == 2 && v[i].second == 1 ||v[i].first == 3 && v[i].second == 2)cnt++;}ans = max(cnt, ans);cout << ans;return 0;}cs 'BOJ' 카테고리의 다른 글
[1062] 가르침 (0) 2021.10.09 [9184] 신나는 함수 실행 (0) 2021.10.08 [12851] 숨바꼭질 2 (0) 2021.10.08 [13549] 숨바꼭질 3 (0) 2021.10.08 [1005] ACM Craft (0) 2021.10.07