๋ฐ์ํ
๋ฌธ์
ํ์ด
๋จ์ํ win-lose ๊ฐ์์ ๋ฌด์น๋ถ ๊ฐ์๋ง ๋ง์ถ๋ฉด ๋๋ค๊ณ ์๊ฐํ๋ค๋ฉด ๋ฐ๋ก ์คํจ
1. ๊ฐ๋ฅํ ๋งค์น๋ค์ ๋ชจ๋ ์ดํด ๋ณด์์ผ ํจ: A - B,C,D,E,F / B-C,D,E,F / C-D,E,F / D-E,F / E-F
2. ๋งค์น๋ฅผ ๋๋ฉฐ ์น-ํจ / ๋ฌด-๋ฌด / ํจ-์น ์ ๊ฒฝ์ฐ๋ฅผ ์ดํด๋ด
3. ์ฌ๊ท๊ฐ 15ํ(์ด ๊ฒฝ๊ธฐ ํ์)๋ ๊ฒฝ์ฐ: ์ ํจํ ๊ฒฝ๊ธฐ ๊ฒฐ๊ณผ!
์ฝ๋
๋๋ณด๊ธฐ
import java.util.*;
import java.io.*;
public class Main {
static final int T = 4; // ํ
์คํธ ์ผ์ด์ค ์
static int[][] game;
static int[][] match = new int[15][2]; // A-BCDEF / B-CDEF ... ์ ์ฅ
static boolean isPossible;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int idx = 0;
for(int i = 0 ; i < 6 ; i++){
for(int j = i+1 ; j < 6 ; j ++){
match[idx][0] = i;
match[idx][1] = j;
idx++;
}
}
tc:for(int tc = 0 ; tc<T ; tc++){
StringTokenizer st = new StringTokenizer(br.readLine());
game = new int[6][3];
for(int i = 0 ; i < 6 ; i++){
int win = Integer.parseInt(st.nextToken());
int draw = Integer.parseInt(st.nextToken());
int lose = Integer.parseInt(st.nextToken());
if(win + draw + lose != 5){ // ํ ํ๋น ๊ฒฝ๊ธฐ์๊ฐ 5๊ฐ ๋์ ๊ฒฝ์ฐ
System.out.print("0 "); continue tc;
}
game[i][0] = win;
game[i][1] = draw;
game[i][2] = lose;
}
isPossible = false;
doGame(0);
System.out.print(isPossible?"1 ":"0 ");
}
}
/*
๋ง์ฝ ์ ํจํ์ง ์์ ๊ฒฝ๊ธฐ ๊ฒฐ๊ณผ๋ผ๋ฉด, round 15ํ๋ฅผ ๋์ง ๋ชปํ ์ฑ ๋๋จ
*/
private static void doGame(int round) {
if(round == 15){ // ์ ํจํ ๊ฒฝ๊ธฐ ๊ฒฐ๊ณผ
isPossible = true;
return;
}
int t1 = match[round][0];
int t2 = match[round][1];
// ๊ฐ ํ์ ์น/ํจ/๋ฌด cnt๊ฐ ๋จ์์์ด์ผ ํจ
if(game[t1][0] > 0 && game[t2][2] > 0){ // t1: ์น / t2: ํจ
game[t1][0] --; game[t2][2] --;
doGame(round+1);
game[t1][0] ++; game[t2][2] ++; // ๋ค์ ๋๋ ค๋๊ณ ๋ค์ ๊ฒฝ์ฐ ์คํ
}
if(game[t1][1] > 0 && game[t2][1] > 0){ // t1: ๋ฌด / t2: ๋ฌด
game[t1][1] --; game[t2][1] --;
doGame(round+1);
game[t1][1] ++; game[t2][1] ++;
}
if(game[t1][2] > 0 && game[t2][0] > 0){ // t1: ํจ / t2: ์น
game[t1][2] --; game[t2][0] --;
doGame(round+1);
game[t1][2] ++; game[t2][0] ++;
}
}
}
๋ฐ์ํ
'๐ ์๊ณ ๋ฆฌ์ฆ > BruteForce' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 14658๋ฒ: ํ๋์์ ๋ณ๋ฅ๋ณ์ด ๋น๋ฐ์น๋ค (Java) (0) | 2022.04.12 |
---|---|
[SWEA] 3234๋ฒ ์คํ์ด์ ์ํ์ ์ธ(java) (0) | 2021.08.20 |
[SWEA] 4012๋ฒ ์๋ฆฌ์ฌ, [๋ฐฑ์ค] 14889๋ฒ ์คํํธ์ ๋งํฌ (0) | 2021.08.18 |
[๋ฐฑ์ค] 2961๋ฒ ๋์์ด๊ฐ ๋ง๋ ๋ง์๋ ์์ (0) | 2021.08.17 |
[๋ฐฑ์ค]17281๋ฒ โพ(์ผ๊ตฌ) (0) | 2021.08.17 |