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 64a1adf

Browse files
authored
Merge pull request #304 from GreatAlgorithm-Study/jimin
[22주차] 손지민
2 parents 772d9c4 + 4598e74 commit 64a1adf

File tree

6 files changed

+318
-0
lines changed

6 files changed

+318
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.StringTokenizer;
7+
8+
public class JM_1707 {
9+
static int V;
10+
static int E;
11+
static List<List<Integer>> graph;
12+
13+
private static boolean dfs(int g, int curr, int[] groups) {
14+
groups[curr] = g;
15+
for(int next : graph.get(curr)) {
16+
if(groups[curr] == groups[next]) return false;
17+
if(groups[next] == 0 && !dfs(3 - g, next, groups)) return false;
18+
}
19+
return true;
20+
}
21+
22+
private static boolean isBinaryGraph() {
23+
int[] groups = new int[V + 1];
24+
for (int i = 1; i <= V; i++) {
25+
if(groups[i] != 0) continue;
26+
if(!dfs(1, i, groups)) return false;
27+
}
28+
return true;
29+
}
30+
31+
public static void main(String[] args) throws IOException {
32+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
33+
StringTokenizer st = new StringTokenizer(br.readLine());
34+
int K = Integer.parseInt(st.nextToken());
35+
36+
StringBuilder sb = new StringBuilder();
37+
while (K-- > 0) {
38+
st = new StringTokenizer(br.readLine());
39+
V = Integer.parseInt(st.nextToken());
40+
E = Integer.parseInt(st.nextToken());
41+
graph = new ArrayList<>();
42+
for (int i = 0; i <= V; i++) {
43+
graph.add(new ArrayList<>());
44+
}
45+
for (int i = 0; i < E; i++) {
46+
st = new StringTokenizer(br.readLine());
47+
int u = Integer.parseInt(st.nextToken());
48+
int v = Integer.parseInt(st.nextToken());
49+
graph.get(u).add(v);
50+
graph.get(v).add(u);
51+
}
52+
sb.append(isBinaryGraph() ? "YES" : "NO").append("\n");
53+
}
54+
System.out.println(sb);
55+
}
56+
}

‎BOJ/10001-15000번/JM_16724.java‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class JM_16724 {
7+
static int N;
8+
static int M;
9+
static final int[][] DIR = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
10+
static int[][] map;
11+
static int cycle;
12+
13+
private static void dfs(int y, int x, boolean[][] visited, boolean[][] finished) {
14+
visited[y][x] = true;
15+
16+
int ny = y + DIR[map[y][x]][0];
17+
int nx = x + DIR[map[y][x]][1];
18+
19+
if(!visited[ny][nx]) dfs(ny, nx, visited, finished);
20+
else if(!finished[ny][nx]) cycle++;
21+
22+
finished[y][x] = true;
23+
}
24+
25+
private static int solve() {
26+
cycle = 0;
27+
boolean[][] visited = new boolean[N][M];
28+
boolean[][] finished = new boolean[N][M];
29+
for (int i = 0; i < N; i++) {
30+
for (int j = 0; j < M; j++) {
31+
if (visited[i][j])
32+
continue;
33+
dfs(i, j, visited, finished);
34+
}
35+
}
36+
return cycle;
37+
}
38+
39+
private static int getDir(char dir) {
40+
if(dir == 'U') return 0;
41+
else if(dir == 'D') return 1;
42+
else if(dir == 'L') return 2;
43+
return 3;
44+
}
45+
46+
public static void main(String[] args) throws IOException {
47+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
48+
StringTokenizer st = new StringTokenizer(br.readLine());
49+
N = Integer.parseInt(st.nextToken());
50+
M = Integer.parseInt(st.nextToken());
51+
map = new int[N][M];
52+
53+
for (int i = 0; i < N; i++) {
54+
char[] tmp = br.readLine().toCharArray();
55+
for (int j = 0; j < M; j++) {
56+
map[i][j] = getDir(tmp[j]);
57+
}
58+
}
59+
System.out.println(solve());
60+
}
61+
}

‎BOJ/10001-15000번/JM_18430.java‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class JM_18430 {
7+
static int N;
8+
static int M;
9+
static int[][] tree;
10+
static int answer;
11+
static final int[][][] boomerang = {
12+
{{0, -1}, {1, 0}},
13+
{{-1, 0}, {0, -1}},
14+
{{-1, 0}, {0, 1}},
15+
{{0, 1}, {1, 0}}
16+
};
17+
18+
private static boolean inRange(int y, int x) {
19+
return 0 <= y && y < N && 0 <= x && x < M;
20+
}
21+
22+
private static void solve(int index, int totalSum, boolean[][] check) {
23+
if(index == N * M) {
24+
answer = Math.max(answer, totalSum);
25+
return;
26+
}
27+
28+
int y = index / M;
29+
int x = index % M;
30+
31+
if(check[y][x]) {
32+
solve(index + 1, totalSum, check);
33+
return;
34+
}
35+
36+
check[y][x] = true;
37+
for (int i = 0; i < 4; i++) {
38+
int y1 = y + boomerang[i][0][0];
39+
int x1 = x + boomerang[i][0][1];
40+
int y2 = y + boomerang[i][1][0];
41+
int x2 = x + boomerang[i][1][1];
42+
43+
if(!inRange(y1, x1) || !inRange(y2, x2)) continue;
44+
if(check[y1][x1] || check[y2][x2]) continue;
45+
46+
check[y1][x1] = true;
47+
check[y2][x2] = true;
48+
int currSum = tree[y][x] * 2 + tree[y1][x1] + tree[y2][x2];
49+
solve(index + 1, totalSum + currSum, check);
50+
check[y1][x1] = false;
51+
check[y2][x2] = false;
52+
}
53+
check[y][x] = false;
54+
55+
solve(index + 1, totalSum, check);
56+
}
57+
58+
public static void main(String[] args) throws IOException {
59+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
60+
StringTokenizer st = new StringTokenizer(br.readLine());
61+
N = Integer.parseInt(st.nextToken());
62+
M = Integer.parseInt(st.nextToken());
63+
64+
tree = new int[N][M];
65+
for (int i = 0; i < N; i++) {
66+
st = new StringTokenizer(br.readLine());
67+
for (int j = 0; j < M; j++) {
68+
tree[i][j] = Integer.parseInt(st.nextToken());
69+
}
70+
}
71+
72+
solve(0, 0, new boolean[N][M]);
73+
System.out.println(answer);
74+
}
75+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class JM_병원_거리_최소화하기 {
5+
static class Point {
6+
int y, x;
7+
public Point(int y, int x) {
8+
this.y = y;
9+
this.x = x;
10+
}
11+
}
12+
static int N;
13+
static int M;
14+
static List<Point> hospital;
15+
static List<Point> person;
16+
static int answer;
17+
static int[][] dist;
18+
19+
private static int calc(int picked) {
20+
int sum = 0;
21+
for(int i = 0; i < person.size(); i++) {
22+
int pDist = Integer.MAX_VALUE;
23+
for(int j = 0; j < hospital.size(); j++) {
24+
if((picked & (1 << j)) == 0) continue;
25+
if(pDist > dist[i][j]) pDist = dist[i][j];
26+
}
27+
sum += pDist;
28+
}
29+
return sum;
30+
}
31+
32+
private static void pick(int next, int index, int picked) {
33+
if(index == M) {
34+
int currTotalSum = calc(picked);
35+
if(answer > currTotalSum) answer = currTotalSum;
36+
return;
37+
}
38+
39+
for(int i = next; i < hospital.size(); i++) {
40+
pick(i + 1, index + 1, picked | (1 << i));
41+
}
42+
43+
}
44+
45+
private static void initDist() {
46+
for(int i = 0; i < person.size(); i++) {
47+
for(int j = 0; j < hospital.size(); j++) {
48+
dist[i][j] = Math.abs(person.get(i).y - hospital.get(j).y) + Math.abs(person.get(i).x - hospital.get(j).x);
49+
}
50+
}
51+
}
52+
53+
public static void main(String[] args) throws IOException {
54+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
55+
StringTokenizer st = new StringTokenizer(br.readLine());
56+
N = Integer.parseInt(st.nextToken());
57+
M = Integer.parseInt(st.nextToken());
58+
59+
hospital = new ArrayList<>();
60+
person = new ArrayList<>();
61+
62+
for(int i = 0; i < N; i++) {
63+
st = new StringTokenizer(br.readLine());
64+
for(int j = 0; j < N; j++) {
65+
int x = Integer.parseInt(st.nextToken());
66+
if(x == 1) person.add(new Point(i, j));
67+
else if(x == 2) hospital.add(new Point(i, j));
68+
}
69+
}
70+
71+
dist = new int[person.size()][hospital.size()];
72+
initDist();
73+
74+
answer = Integer.MAX_VALUE;
75+
pick(0, 0, 0);
76+
System.out.println(answer);
77+
}
78+
}

‎Programmers/Level3/JM_67258.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
3+
// 모든 보석을 하나 이상 포함하는 가장 짧은 구간
4+
class JM_67824 {
5+
public static int[] findShortest(String[] gems, int gemCount) {
6+
int[] answer = {-1, -1};
7+
Map<String, Integer> map = new HashMap<>();
8+
9+
int l = 0, r = 0;
10+
while(l < gems.length && r < gems.length) {
11+
map.put(gems[r], map.getOrDefault(gems[r], 0) + 1);
12+
13+
while(map.size() == gemCount && l <= r) {
14+
if(answer[0] == -1 || (answer[1] - answer[0]) > (r - l)) {
15+
answer[0] = l + 1;
16+
answer[1] = r + 1;
17+
}
18+
if(map.get(gems[l]) == 1) map.remove(gems[l]);
19+
else map.put(gems[l], map.get(gems[l]) - 1);
20+
l++;
21+
}
22+
r++;
23+
}
24+
25+
return answer;
26+
}
27+
28+
public static int[] solution(String[] gems) {
29+
Set<String> set = new HashSet<String>(Arrays.asList(gems));
30+
int gemCount = set.size();
31+
return findShortest(gems, gemCount);
32+
}
33+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SELECT
2+
a.AUTHOR_ID,
3+
a.AUTHOR_NAME,
4+
b.CATEGORY,
5+
SUM(bs.SALES * b.PRICE) AS TOTAL_SALES
6+
FROM
7+
BOOK_SALES bs
8+
JOIN BOOK b ON bs.BOOK_ID = b.BOOK_ID
9+
JOIN AUTHOR a ON b.AUTHOR_ID = a.AUTHOR_ID
10+
WHERE
11+
bs.SALES_DATE BETWEEN '2022年01月01日' AND '2022年01月31日'
12+
GROUP BY
13+
a.AUTHOR_ID, b.CATEGORY
14+
ORDER BY
15+
a.AUTHOR_ID, b.CATEGORY DESC;

0 commit comments

Comments
(0)

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