-
Notifications
You must be signed in to change notification settings - Fork 4
[15주차] 고다혜 #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
[15주차] 고다혜 #209
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0da6e94
고다혜: [BOJ] 1882 쿼드트리_241217
KodaHye e90282c
고다혜: [BOJ] 1030 프렉탈 평면_241217
KodaHye b37b16f
고다혜: [SQL] Odd And Even Transactions_241217
KodaHye eb2e66c
고다혜: [BOJ] 9372 상근이의 여행_241219
KodaHye cf3a546
고다혜: [BOJ] 4803 트리_241219
KodaHye a163106
고다혜: [PG] 42892 길 찾기 게임_241220
KodaHye 9936cb5
고다혜: [BOJ] 1725 히스토그램_241218
KodaHye 268a95f
고다혜: [CT] 윷놀이 사기단_241216
KodaHye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
CodeTree/2019-2020년/DH_윷놀이_사기단.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class DH_윷놀이_사기단 { | ||
static final int TURN = 10; | ||
static int[] arr, sel; // 중복 순열 | ||
static int[][] map; | ||
static class Horse { | ||
int r, c; | ||
public Horse() {} | ||
@Override | ||
public String toString() { | ||
return "Horse [r=" + r + ", c=" + c + "]"; | ||
} | ||
} | ||
static int maxResult; | ||
static boolean[] v; | ||
static Horse[] horses; | ||
|
||
public static void main(String[] args) throws Exception { | ||
horses = new Horse[5]; | ||
v = new boolean[5]; | ||
for(int i = 0; i < horses.length; i++) horses[i] = new Horse(); | ||
|
||
map = new int[][]{ | ||
{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 41}, | ||
{10, 13, 16, 19, 25, 30, 35, 40, 41}, | ||
{20, 22, 24, 25, 30, 35, 40, 41}, | ||
{30, 28, 27, 26, 25, 30, 35, 40, 41}}; | ||
|
||
initInput(); | ||
solution(); | ||
System.out.println(maxResult); | ||
} | ||
|
||
|
||
static void solution() { | ||
sel = new int[10]; | ||
func(0, 0); | ||
} | ||
|
||
static void func(int depth, int result) { | ||
if(depth == TURN) { | ||
maxResult = Math.max(maxResult, result); | ||
return; | ||
} | ||
|
||
for(int i = 1; i < 5; i++) { | ||
if(v[i]) continue; | ||
sel[depth] = i; | ||
|
||
int currentR = horses[i].r; | ||
int currentC = horses[i].c; | ||
|
||
int nr = currentR; | ||
int nc = currentC + arr[depth]; | ||
|
||
if(nc >= map[nr].length) { | ||
nc = map[nr].length - 1; | ||
v[i] = true; | ||
} else { | ||
if(map[nr][nc] == 10 || map[nr][nc] == 20 || | ||
(map[nr][nc] == 30 && map[nr][nc - 1] == 28)) { | ||
nr = map[nr][nc] / 10; | ||
nc = 0; | ||
} | ||
|
||
boolean canGo = true; | ||
|
||
for(int j = 1; j < 5; j++) { | ||
if(j == i) continue; | ||
if(map[horses[i].r][horses[i].c] == 0 || map[horses[j].r][horses[j].c] == 0) continue; | ||
if(map[horses[i].r][horses[i].c] == 41 || map[horses[j].r][horses[j].c] == 41) continue; | ||
|
||
if(nr == horses[j].r && nc == horses[j].c) { | ||
canGo = false; | ||
break; | ||
} | ||
} | ||
|
||
if(!canGo) continue; | ||
} | ||
|
||
horses[i].r = nr; | ||
horses[i].c = nc; | ||
|
||
func(depth + 1, result + (map[nr][nc] % 41)); | ||
|
||
horses[i].r = currentR; | ||
horses[i].c = currentC; | ||
|
||
if(currentC < map[currentR].length) { | ||
v[i] = false; | ||
} | ||
} | ||
} | ||
|
||
static void initInput() throws Exception { | ||
System.setIn(new FileInputStream("./input/윶놀이사기단.txt")); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
arr = new int[10]; | ||
for(int i = 0; i < 10; i++) arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.