Skip to content

Commit e726186

Browse files
committed
[Permutation] swea-6808
1 parent 84cc619 commit e726186

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

โ€ŽREADME.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
| 05 | | [Baekjoon-11404 ํ”Œ๋กœ์ด๋“œ](./src/Graph/P11404) | Floyd-Warshall |
194194
| 06 | | [Baekjoon-1854 K๋ฒˆ์งธ ์ตœ๋‹จ๊ฒฝ๋กœ ์ฐพ๊ธฐ](./src/Graph/P1854) | Dijkstra |
195195
| 07 | | [Baekjoon-3860 ํ• ๋กœ์œˆ ๋ฌ˜์ง€](./src/Graph/P3860) | Bellman-Ford |
196-
| 06 | โญ๏ธ | [Baekjoon-5719 ๊ฑฐ์˜ ์ตœ๋‹จ ๊ฒฝ๋กœ](./src/Graph/P5719) | Dijkstra |
196+
| 08 | โญ๏ธ | [Baekjoon-5719 ๊ฑฐ์˜ ์ตœ๋‹จ ๊ฒฝ๋กœ](./src/Graph/P5719) | Dijkstra |
197197

198198
### Union-Find
199199

@@ -242,6 +242,7 @@
242242
| 04 | | [Baekjoon-10973 ์ด์ „ ์ˆœ์—ด](./src/Permutation/P10973) | |
243243
| 05 | | [Baekjoon-10974 ๋ชจ๋“  ์ˆœ์—ด](./src/Permutation/P10974) | |
244244
| 06 | | [Baekjoon-9742 ์ˆœ์—ด](./src/Permutation/P9742) | |
245+
| 07 | | [SWEA-6808 ๊ทœ์˜์ด์™€ ์ธ์˜์ด์˜ ์นด๋“œ๊ฒŒ์ž„](./src/Permutation/swea6808) | |
245246

246247
### Probability
247248

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## [SW Expert Academy - 6808] ๊ทœ์˜์ด์™€ ์ธ์˜์ด์˜ ์นด๋“œ๊ฒŒ์ž„
2+
3+
![image](https://user-images.githubusercontent.com/22045163/107907524-4b5c0a00-6f97-11eb-9199-21c58a642ae3.png)
4+
![image](https://user-images.githubusercontent.com/22045163/107907540-557e0880-6f97-11eb-8fea-5c0e545ac5d6.png)
5+
6+
![image](https://user-images.githubusercontent.com/22045163/107907575-675fab80-6f97-11eb-8796-dca1fe2e5b9f.png)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package Permutation.swea6808;
2+
3+
import java.io.*;
4+
import java.util.StringTokenizer;
5+
6+
public class Solution {
7+
8+
static int T;
9+
static int[] c1 = new int[9], c2 = new int[9];
10+
11+
public static void main(String[] args) throws Exception {
12+
System.setIn(new FileInputStream("src/Permutation/swea6808/s_input.txt"));
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringBuilder sb = new StringBuilder();
15+
16+
T = Integer.parseInt(br.readLine());
17+
for (int t = 1; t <= T; t++) {
18+
StringTokenizer st = new StringTokenizer(br.readLine());
19+
boolean[] nums = new boolean[19];
20+
for (int i = 0; i < 9; i++) {
21+
c1[i] = Integer.parseInt(st.nextToken());
22+
nums[c1[i]] = true;
23+
}
24+
25+
for (int i = 1, j = 0; i <= 18; i++) {
26+
if (!nums[i]) c2[j++] = i;
27+
}
28+
29+
int win = 0, lose = 0;
30+
do {
31+
int sc1 = 0, sc2 = 0;
32+
for (int i = 0; i < 9; i++) {
33+
if (c1[i] > c2[i]) sc1 += c1[i] + c2[i];
34+
else sc2 += c1[i] + c2[i];
35+
}
36+
if (sc1 > sc2) win ++;
37+
else if (sc1 < sc2) lose ++;
38+
} while (np());
39+
40+
sb.append("#").append(t).append(" ").append(win).append(" ").append(lose).append("\n");
41+
}
42+
43+
System.out.println(sb.toString());
44+
}
45+
46+
static boolean np() {
47+
int i = 8;
48+
while (i > 0 && c2[i-1] > c2[i]) i--;
49+
if (i == 0) return false;
50+
51+
int j = 8;
52+
while (c2[i-1] > c2[j]) j--;
53+
swap(i-1, j);
54+
55+
int k = 8;
56+
while (i < k) swap(i++, k--);
57+
return true;
58+
}
59+
60+
static void swap(int i, int j) {
61+
int tmp = c2[i];
62+
c2[i] = c2[j];
63+
c2[j] = tmp;
64+
}
65+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 3 5 7 9 11 13 15 17
3+
18 16 14 12 10 8 6 4 2
4+
13 17 9 5 18 7 11 1 15
5+
1 6 7 9 12 13 15 17 18
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#1 112097 250783
2+
#2 250783 112097
3+
#3 336560 26320
4+
#4 346656 16224

0 commit comments

Comments
ย (0)