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, 2, 3을 가위, 바위, 보로 적절히 분배하여 첫 번째 소가 이길 수 있는 최대 게임 수를 출력합니다.
race를 지정할 수 있는 경우의 수는 3! = 6가지
게임 수는 최대 100게임
따라서 브루트포스로 해결할 수 있습니다.
nextPermutation으로 race의 모든 경우를 확인할 수 있고, 그 때마다 첫 번째 소가 얻을 수 있는 점수를 구합니다.
그리고 그것들의 최댓값을 구하여 출력합니다.
| 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main {     private final static int MAX = 100;     private final static int RACE_CNT = 3;     private static int race[] = {1, 2, 3};     private static int list[][] = new int[MAX][2];     private static int N;     private static void swap(int i, int j) {         int tmp = race[i];         race[i] = race[j];         race[j] = tmp;     }     private static boolean nextPermutation() {         int i = RACE_CNT - 1;         while (i > 0 && race[i - 1] > race[i]) {             i--;         }         if (i == 0) {             return false;         }         int j = RACE_CNT - 1;         while (race[i - 1] > race[j]) {             j--;         }         swap(i - 1, j);         int k = RACE_CNT - 1;         while (i < k) {             swap(i++, k--);         }         return true;     }     private static int getScore(int x, int y) {         if (x == 1 && y == 2) {             return 1;         } else if (x == 2 && y == 3) {             return 1;         } else if (x == 3 && y == 1) {             return 1;         } else {             return 0;         }     }     private static void func() {         int ans = 0;         do {             int ret = 0;             for (int i = 0; i < N; i++) {                 ret += getScore(race[list[i][0] - 1], race[list[i][1] - 1]);             }             ans = Math.max(ans, ret);         } while (nextPermutation());         System.out.println(ans);     }     private static void input() throws Exception {         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         StringTokenizer st = new StringTokenizer(br.readLine());         N = Integer.parseInt(st.nextToken());         for (int i = 0; i < N; i++) {             st = new StringTokenizer(br.readLine());             list[i][0] = Integer.parseInt(st.nextToken());             list[i][1] = Integer.parseInt(st.nextToken());         }     }     public static void main(String[] args) throws Exception {         input();         func();     } } | cs | 
'algorithm > Bruteforce' 카테고리의 다른 글
| boj 17281 ⚾ (0) | 2021.02.16 | 
|---|---|
| boj 3040 백설 공주와 일곱 난쟁이 (0) | 2021.02.15 | 
| boj 2961 도영이가 만든 맛있는 음식 (0) | 2021.02.15 | 
| boj 2422 한윤정이 이탈리아에 가서 아이스크림을 사먹는데 (0) | 2021.01.29 | 
| boj 1018 체스판 다시 칠하기 (0) | 2021.01.29 |