Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84f73bd

Browse files
Merge pull request #135 from yeongleej/main
[10주차] 이지영
2 parents 970501f + 41d56e3 commit 84f73bd

File tree

9 files changed

+696
-0
lines changed

9 files changed

+696
-0
lines changed

‎BOJ/1000-5000번/JY_1613.java‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package day1113;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class JY_1613 {
7+
8+
static final int INF = 50_000;
9+
10+
public static void main(String[] args) throws IOException{
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
14+
int N = Integer.parseInt(st.nextToken());
15+
int K = Integer.parseInt(st.nextToken());
16+
17+
int[][] g = new int[N+1][N+1];
18+
for(int i=0; i<N+1; i++) {
19+
Arrays.fill(g[i], INF);
20+
}
21+
// 자신으로가는 비용은 0으로 처리
22+
for(int i=1; i<N+1; i++) {
23+
for(int j=1; j<N+1; j++) {
24+
if(i == j) g[i][j] = 0;
25+
}
26+
}
27+
28+
for(int i=0; i<K; i++) {
29+
st = new StringTokenizer(br.readLine());
30+
int a = Integer.parseInt(st.nextToken());
31+
int b = Integer.parseInt(st.nextToken());
32+
33+
g[a][b] = 1;
34+
}
35+
36+
// 플로이드 와샬: i -> j로 갈 수 있는 최단거리 구함
37+
for(int k=1; k<N+1; k++) {
38+
for(int i=1; i<N+1; i++) {
39+
for(int j=1; j<N+1; j++) {
40+
g[i][j] = Math.min(g[i][j], g[i][k]+g[k][j]);
41+
}
42+
}
43+
}
44+
45+
46+
st = new StringTokenizer(br.readLine());
47+
int S = Integer.parseInt(st.nextToken());
48+
49+
StringBuilder sb = new StringBuilder();
50+
for(int s=0; s<S; s++) {
51+
st = new StringTokenizer(br.readLine());
52+
int a = Integer.parseInt(st.nextToken());
53+
int b = Integer.parseInt(st.nextToken());
54+
55+
if(g[a][b] != INF) {
56+
sb.append("-1\n");
57+
} else if(g[b][a] != INF) {
58+
sb.append("1\n");
59+
} else {
60+
sb.append("0\n");
61+
}
62+
}
63+
64+
System.out.println(sb.toString());
65+
66+
}
67+
68+
}

‎BOJ/1000-5000번/JY_2096.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package day1113;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class JY_2096 {
7+
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
12+
int N = Integer.parseInt(st.nextToken());
13+
int[][] dp1 = new int[N][3];
14+
int[][] dp2 = new int[N][3];
15+
16+
for(int i=0; i<N; i++) {
17+
st = new StringTokenizer(br.readLine());
18+
dp1[i][0] = Integer.parseInt(st.nextToken());
19+
dp1[i][1] = Integer.parseInt(st.nextToken());
20+
dp1[i][2] = Integer.parseInt(st.nextToken());
21+
}
22+
23+
for(int i=0; i<N; i++) {
24+
dp2[i][0] = dp1[i][0];
25+
dp2[i][1] = dp1[i][1];
26+
dp2[i][2] = dp1[i][2];
27+
}
28+
29+
for(int i=1; i<N; i++) {
30+
dp1[i][0] = dp1[i][0] + Math.min(dp1[i-1][0], dp1[i-1][1]);
31+
dp1[i][1] = dp1[i][1] + Math.min(dp1[i-1][0], Math.min(dp1[i-1][1], dp1[i-1][2]));
32+
dp1[i][2] = dp1[i][2] + Math.min(dp1[i-1][1], dp1[i-1][2]);
33+
34+
dp2[i][0] = dp2[i][0] + Math.max(dp2[i-1][0], dp2[i-1][1]);
35+
dp2[i][1] = dp2[i][1] + Math.max(dp2[i-1][0], Math.max(dp2[i-1][1], dp2[i-1][2]));
36+
dp2[i][2] = dp2[i][2] + Math.max(dp2[i-1][1], dp2[i-1][2]);
37+
}
38+
39+
int max = Math.max(dp2[N-1][0], Math.max(dp2[N-1][1], dp2[N-1][2]));
40+
int min = Math.min(dp1[N-1][0], Math.min(dp1[N-1][1], dp1[N-1][2]));
41+
42+
System.out.println(max+" "+min);
43+
44+
}
45+
46+
}

‎BOJ/1000-5000번/JY_2955.java‎

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package day1112;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class JY_2955 {
7+
8+
static final int N = 9;
9+
static int[][] g;
10+
static boolean[][] visited;
11+
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
15+
g = new int[N][N];
16+
for(int i=0; i<N; i++) {
17+
String s = br.readLine();
18+
for(int j=0; j<N; j++) {
19+
if(s.charAt(j) == '.') {
20+
g[i][j] = 0;
21+
} else {
22+
g[i][j] = s.charAt(j) - '0';
23+
}
24+
}
25+
}
26+
27+
28+
29+
// cross hatching
30+
while(true) {
31+
boolean isDone = true;
32+
33+
for(int n=1; n<=9; n++) {
34+
// 유효성 체크
35+
if(!isValid(n)) {
36+
System.out.println("ERROR");
37+
return;
38+
}
39+
int cnt = crossHatching(n);
40+
if(cnt > 0) isDone = false;
41+
}
42+
43+
if(isDone) break;
44+
45+
}
46+
47+
printS();
48+
49+
}
50+
public static void printG() {
51+
for(int i=0; i<N; i++) {
52+
System.out.println(Arrays.toString(g[i]));
53+
}
54+
System.out.println();
55+
}
56+
public static void printV() {
57+
for(int i=0; i<N; i++) {
58+
System.out.println(Arrays.toString(visited[i]));
59+
}
60+
System.out.println();
61+
}
62+
public static void printS() {
63+
for(int i=0; i<N; i++) {
64+
for(int j=0; j<N; j++) {
65+
if(g[i][j] == 0) System.out.print(".");
66+
else System.out.print(g[i][j]);
67+
}
68+
System.out.println();
69+
}
70+
}
71+
public static void fillLine(int x, int y) {
72+
// 세로줄
73+
for(int i=0; i<N; i++) {
74+
visited[i][y] = true;
75+
}
76+
77+
// 가로줄
78+
for(int j=0; j<N; j++) {
79+
visited[x][j] = true;
80+
}
81+
82+
}
83+
public static void fillSquare(int sx, int sy) {
84+
// 3*3
85+
for(int i=sx; i<sx+3; i++) {
86+
for(int j=sy; j<sy+3; j++) {
87+
visited[i][j] = true;
88+
}
89+
}
90+
}
91+
public static void fillArea(int n) {
92+
for(int i=0; i<N; i += 3) {
93+
for(int j=0; j<N; j += 3) {
94+
for(int x=i; x<i+3; x++) {
95+
for(int y=j; y<j+3; y++) {
96+
if(g[x][y] == n) {
97+
fillLine(x, y);
98+
fillSquare(i, j);
99+
}
100+
if(g[x][y] != 0) {
101+
visited[x][y] = true;
102+
}
103+
}
104+
}
105+
}
106+
}
107+
}
108+
public static boolean checkLine(int n) {
109+
for(int x=0; x<N; x++) {
110+
for(int y=0; y<N; y++) {
111+
if(g[x][y] != n) continue;
112+
113+
// 세로줄 체크
114+
int cnt = 0;
115+
for(int i=0; i<N; i++) {
116+
if(g[i][y] == n) cnt++;
117+
}
118+
if(cnt > 1) return false;
119+
120+
// 기로즐 체크
121+
cnt = 0;
122+
for(int j=0; j<N; j++) {
123+
if(g[x][j] == n) cnt++;
124+
}
125+
if(cnt > 1) return false;
126+
127+
}
128+
}
129+
return true;
130+
}
131+
public static boolean checkBox(int n) {
132+
// 유효한 3 * 3 찾기
133+
for(int i=0; i<N; i+=3) {
134+
for(int j=0; j<N; j += 3) {
135+
int cnt = 0;
136+
int empty = 0;
137+
for(int x=i; x<i+3; x++) {
138+
for(int y=j; y<j+3; y++) {
139+
if(g[x][y] == n) cnt++;
140+
if(!visited[x][y]) empty++;
141+
}
142+
}
143+
144+
if(cnt > 1) return false;
145+
if(cnt == 0 && empty == 0) return false;
146+
}
147+
}
148+
return true;
149+
}
150+
public static boolean isValid(int n) {
151+
visited = new boolean[N][N];
152+
153+
fillArea(n);
154+
155+
return checkBox(n) && checkLine(n);
156+
}
157+
public static int findSpot(int n) {
158+
// 유효한 3 * 3 찾기
159+
int fCnt = 0;
160+
for(int i=0; i<N; i+=3) {
161+
for(int j=0; j<N; j += 3) {
162+
int cnt = 0;
163+
int empty = 0;
164+
int px = -1, py = -1;
165+
for(int x=i; x<i+3; x++) {
166+
for(int y=j; y<j+3; y++) {
167+
if(g[x][y] == n) cnt++;
168+
if(!visited[x][y]) {
169+
empty++;
170+
px = x;
171+
py = y;
172+
}
173+
}
174+
}
175+
// n이없고, 빈곳이 1개이면 => CrossHatching
176+
if(cnt == 0 && empty == 1) {
177+
visited[px][py] = true;
178+
g[px][py] = n;
179+
fillLine(px, py);
180+
fCnt++;
181+
}
182+
}
183+
}
184+
return fCnt;
185+
}
186+
public static int crossHatching(int n) {
187+
visited = new boolean[N][N];
188+
fillArea(n);
189+
190+
191+
return findSpot(n);
192+
}
193+
194+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /