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 4e4082e

Browse files
Merge pull request #231 from yeongleej/main
[17주차] 이지영
2 parents 8fe7264 + ac7988b commit 4e4082e

File tree

8 files changed

+562
-0
lines changed

8 files changed

+562
-0
lines changed

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class JY_1765 {
5+
6+
static int N, M;
7+
static List<Integer>[] eList;
8+
static int[] parent;
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+
N = Integer.parseInt(st.nextToken());
15+
16+
eList = new ArrayList[N+1];
17+
parent = new int[N+1];
18+
for(int i=1; i<N+1; i++) {
19+
eList[i] = new ArrayList<>();
20+
parent[i] = i;
21+
}
22+
23+
st = new StringTokenizer(br.readLine());
24+
M = Integer.parseInt(st.nextToken());
25+
for(int m=0; m<M; m++) {
26+
st = new StringTokenizer(br.readLine());
27+
String type = st.nextToken();
28+
int a = Integer.parseInt(st.nextToken());
29+
int b = Integer.parseInt(st.nextToken());
30+
31+
// 1) 친구 => 부모 같게
32+
if(type.equals("F")) {
33+
if(find(a) != find(b)) {
34+
union(a, b);
35+
}
36+
}
37+
// 2) 원수 인 경우
38+
else {
39+
// 원수 찾기
40+
// a의 원수
41+
if(!eList[a].isEmpty()) {
42+
int ea = eList[a].get(0);
43+
if(find(ea) != find(b)) union(ea, b);
44+
}
45+
// b의 원수
46+
if(!eList[b].isEmpty()) {
47+
int eb = eList[b].get(0);
48+
if(find(eb) != find(a)) union(eb, a);
49+
}
50+
51+
eList[a].add(b);
52+
eList[b].add(a);
53+
}
54+
}
55+
56+
57+
// 부모 재정비
58+
for(int i=1; i<N+1; i++) {
59+
find(i);
60+
}
61+
62+
// 팀 찾기
63+
Set<Integer> teams = new HashSet<>();
64+
for(int i=1; i<N+1; i++) {
65+
teams.add(parent[i]);
66+
}
67+
68+
System.out.println(teams.size());
69+
70+
71+
72+
}
73+
public static int find(int x) {
74+
if(x != parent[x]) {
75+
parent[x] = find(parent[x]);
76+
}
77+
return parent[x];
78+
}
79+
public static void union(int a, int b) {
80+
int pa = find(a);
81+
int pb = find(b);
82+
if(pa == pb) return;
83+
84+
parent[b] = pa;
85+
}
86+
87+
}

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class JY_3109 {
5+
6+
static int R, C;
7+
static char[][] g;
8+
// 우상, 우, 우하
9+
static int[] dx = {-1, 0, 1};
10+
static int[] dy = {1, 1, 1};
11+
static int ans, cnt;
12+
13+
public static void main(String[] args) throws IOException {
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
StringTokenizer st = new StringTokenizer(br.readLine());
16+
17+
R = Integer.parseInt(st.nextToken());
18+
C = Integer.parseInt(st.nextToken());
19+
20+
g = new char[R][C];
21+
22+
for(int i=0; i<R; i++) {
23+
String line = br.readLine();
24+
for(int j=0; j<C; j++) {
25+
g[i][j] = line.charAt(j);
26+
}
27+
}
28+
29+
// printG();
30+
31+
ans = 0;
32+
for(int i=0; i<R; i++) {
33+
dfs(i, 0);
34+
}
35+
36+
System.out.println(ans);
37+
38+
39+
}
40+
public static void printG() {
41+
for(int i=0; i<R; i++) {
42+
System.out.println(Arrays.toString(g[i]));
43+
}
44+
System.out.println();
45+
}
46+
47+
public static boolean inRange(int x, int y) {
48+
return x>=0 && x<R && y>=0 && y<C;
49+
}
50+
public static boolean dfs(int x, int y) {
51+
g[x][y] = 'x'; // 갔던 곳 방문 처리
52+
53+
if(y == C-1) {
54+
ans++;
55+
// 방향 탐색은 우상 -> 우 -> 우하 순으로 이루어지는데,
56+
// 우상 방향에서 갈 수 있는 모든 방향을 다 탐색 했다면 더 이상 우, 우하 방향은 탐색하지 않아도됨
57+
return true;
58+
}
59+
60+
boolean res = false;
61+
for(int i=0; i<3; i++) {
62+
int nx = x + dx[i];
63+
int ny = y + dy[i];
64+
if(!inRange(nx, ny)) continue;
65+
if(g[nx][ny] == 'x') continue;
66+
67+
res = dfs(nx, ny);
68+
69+
if(res) break;
70+
}
71+
72+
return res;
73+
}
74+
75+
}

‎BOJ/20001-25000번/JY_20061.java‎

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class JY_20061 {
5+
6+
static final int M = 10; // 전체 배열의 크기
7+
static final int R = 4; // 빨간색 보드의 크기
8+
static int N;
9+
static int[][] g;
10+
static int score;
11+
// 블록 벡터(한개블록, 가로블록, 세로블록)
12+
static int[] dx = {0, 0, 1};
13+
static int[] dy = {0, 1, 0};
14+
15+
16+
public static void main(String[] args) throws IOException {
17+
// System.setIn(new FileInputStream("src/monomino.txt"));
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
StringTokenizer st = new StringTokenizer(br.readLine());
20+
21+
N = Integer.parseInt(st.nextToken());
22+
23+
g = new int[M][M];
24+
score = 0;
25+
26+
for(int i=0; i<N; i++) {
27+
st = new StringTokenizer(br.readLine());
28+
int t = Integer.parseInt(st.nextToken());
29+
int x = Integer.parseInt(st.nextToken());
30+
int y = Integer.parseInt(st.nextToken());
31+
32+
// 1) 블럭 놓기
33+
play(t-1, x, y);
34+
35+
// 2) 가득찬 타일 체크
36+
checkGreen();
37+
checkBlue();
38+
39+
40+
// 3) 연한색 부분 체크
41+
checkSpecialGreen();
42+
checkSpecialBlue();
43+
44+
}
45+
46+
// 4) 남아있는 블럭 체크
47+
int cnt = 0;
48+
for(int x=0; x<M; x++) {
49+
for(int y=0; y<M; y++) {
50+
cnt += g[x][y];
51+
}
52+
}
53+
System.out.println(score);
54+
System.out.println(cnt);
55+
56+
}
57+
public static void print() {
58+
for(int i=0; i<M; i++) {
59+
System.out.println(Arrays.toString(g[i]));
60+
}
61+
System.out.println();
62+
}
63+
public static boolean inRange(int x, int y) {
64+
return x>=0 && x<M && y>=0 && y<M;
65+
}
66+
public static boolean isFill(int x, int y, int ox, int oy) {
67+
return inRange(x, y) && inRange(ox, oy) && g[x][y] == 0 && g[ox][oy] == 0;
68+
}
69+
public static void fillGreen(int t, int x, int y) {
70+
int nx = x; // 블록이 놓일 x행 위치
71+
int oy = y + dy[t];
72+
for(int i=R; i<M; i++) {
73+
int ox = i + dx[t];
74+
// 현재 칸에 블록이 있다면 그 이전 행에 블록 놓기
75+
if(!isFill(i, y, ox, oy)) {
76+
nx = i-1;
77+
break;
78+
}
79+
}
80+
if(nx == x) nx = M-1;
81+
g[nx][y] = 1;
82+
g[nx+dx[t]][y+dy[t]] = 1;
83+
84+
}
85+
public static void fillBlue(int t, int x, int y) {
86+
int ny = y; // 블록이 놓일 y열 위치
87+
int ox = x + dx[t];
88+
for(int j=R; j<M; j++) {
89+
int oy = j + dy[t];
90+
// 현재 칸에 블록이 있다면 그 이전 행에 블록 놓기
91+
if(!isFill(x, j, ox, oy)) {
92+
ny = j-1;
93+
break;
94+
}
95+
}
96+
if(ny == y) ny = M-1;
97+
g[x][ny] = 1;
98+
g[x+dx[t]][ny+dy[t]] = 1;
99+
}
100+
public static void play(int t, int x, int y) {
101+
// 초록색 보드 채우기(행)
102+
fillGreen(t, x, y);
103+
104+
// 파란색 보드 채우기(열)
105+
fillBlue(t, x, y);
106+
}
107+
public static void moveRow(int x, int sx) {
108+
// 임시 배열 생성
109+
int[][] tmp = new int[M][M];
110+
for(int i=0; i<M; i++) {
111+
for(int j=0; j<M; j++) {
112+
tmp[i][j] = g[i][j];
113+
}
114+
}
115+
// 기준점 위의 블록들을 한칸 씩 아래로 이동
116+
for(int i=x; i>=sx; i--) {
117+
for(int j=0; j<R; j++) {
118+
tmp[i][j] = g[i-1][j];
119+
}
120+
}
121+
122+
g = tmp;
123+
}
124+
public static void checkGreen() {
125+
int x = R+2;
126+
while(x < M) {
127+
// 열체크
128+
int cnt = 0;
129+
for(int y=0; y<R; y++) {
130+
cnt += g[x][y];
131+
}
132+
// x행이 가득참
133+
if(cnt == R) {
134+
score += 1;
135+
// x행 비우기
136+
Arrays.fill(g[x], 0);
137+
138+
// 한칸씩 이동 시키기
139+
moveRow(x, R+1);
140+
x = R + 2; // 다시 처음부터 탐색
141+
continue;
142+
}
143+
x++;
144+
}
145+
}
146+
public static void moveCol(int y, int sy) {
147+
// 임시 배열 생성
148+
int[][] tmp = new int[M][M];
149+
for(int i=0; i<M; i++) {
150+
for(int j=0; j<M; j++) {
151+
tmp[i][j] = g[i][j];
152+
}
153+
}
154+
// 기준점 왼쪽의 블록들을 한칸 씩 오른쪽으로 이동
155+
for(int j=y; j>=sy; j--) {
156+
for(int i=0; i<R; i++) {
157+
tmp[i][j] = g[i][j-1];
158+
}
159+
}
160+
161+
g = tmp;
162+
}
163+
public static void checkBlue() {
164+
int y = R+2;
165+
while(y < M) {
166+
// 행체크
167+
int cnt = 0;
168+
for(int x=0; x<R; x++) {
169+
cnt += g[x][y];
170+
}
171+
// y열이 가득참
172+
if(cnt == R) {
173+
score += 1;
174+
// y열 비우기
175+
for(int x=0; x<R; x++) {
176+
g[x][y] = 0;
177+
}
178+
179+
// 한칸씩 이동 시키기
180+
moveCol(y, R+1);
181+
y = R + 2; // 다시 처음부터 탐색
182+
continue;
183+
}
184+
y++;
185+
}
186+
}
187+
public static void checkSpecialGreen() {
188+
int cnt = 0;
189+
for(int i=R; i<R+2; i++) {
190+
for(int j=0; j<R; j++) {
191+
if(g[i][j] == 1) {
192+
cnt++;
193+
break;
194+
}
195+
}
196+
}
197+
// 연한칸에 블록 존재
198+
while(cnt > 0) {
199+
// 마지막 행 비우기
200+
Arrays.fill(g[M-1], 0);
201+
202+
// 한칸씩 이동 시키기
203+
moveRow(M-1, R);
204+
cnt--;
205+
}
206+
}
207+
public static void checkSpecialBlue() {
208+
int cnt = 0;
209+
for(int j=R; j<R+2; j++) {
210+
for(int i=0; i<R; i++) {
211+
if(g[i][j] == 1) {
212+
cnt++;
213+
break;
214+
}
215+
}
216+
}
217+
// 연한칸에 블록 존재
218+
while(cnt > 0) {
219+
// 마지막 열 비우기
220+
for(int x=0; x<R; x++) {
221+
g[x][M-1] = 0;
222+
}
223+
224+
// 한칸씩 이동 시키기
225+
moveCol(M-1, R);
226+
cnt--;
227+
}
228+
}
229+
230+
}

0 commit comments

Comments
(0)

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