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 474efec

Browse files
authored
Merge pull request #35 from yeahdy/main
2 parents 0350942 + d45ff9f commit 474efec

7 files changed

+376
-2
lines changed

โ€ŽBOJ/1000-10000๋ฒˆ/YJ_2631.javaโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static void main(String[] args) throws IOException {
2828

2929
static int getMinChanged(int children,int[] line){
3030
int [] dp = new int[children];
31+
int lis = 0;
3132
for(int i=0; i<children; i++){
3233
dp[i] = 1; //์ตœ์†Œ๊ฐ’ 1
3334
for(int j=0; j<i; j++){
@@ -37,8 +38,8 @@ static int getMinChanged(int children,int[] line){
3738
dp[i] = dp[j]+1;
3839
}
3940
}
41+
lis = Math.max(lis,dp[i]);
4042
}
41-
Arrays.sort(dp); //์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ ์‹œ ๋งˆ์ง€๋ง‰ ์ˆ˜๊ฐ€ ์ตœ์žฅ ์ •๋ ฌ ์ˆ˜
42-
return children - dp[children-1];
43+
return children - lis;
4344
}
4445
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import java.util.*;
2+
3+
/**
4+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: Queue O(n^2)
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: 1 โ‰ค n โ‰ค 1,000 ๊ฐœ์˜ ๋ฒ”์œ„์˜ ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ˆ์•ผํ•จ
6+
* ์•„์ด๋””์–ด:
7+
* ํ•œ๋ฒˆ์˜ ๋ฐ˜๋ณต์„ ํ–ˆ์„ ๋•Œ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๊ณผ์ •์„ ์ˆœ์„œ์— ๋งž๊ฒŒ ์ž‘์„ฑํ•ด์•ผํ•จ
8+
* - ๋‹ค๋ฆฌ์— ์žˆ๋Š” ๋ชจ๋“  ํŠธ๋Ÿญ์€ ํ•œ์นธ์”ฉ ์ „์ง„ํ•œ๋‹ค
9+
* - ํ•œ์ปจ์”ฉ ์ „์ง„ ํ–ˆ์„ ๋–ผ "๊ฐ€์žฅ ์•ž์— ์žˆ๋Š” ํŠธ๋Ÿญ"์ด ๋‹ค๋ฆฌ์˜ ๊ธธ์ด๊นŒ์ง€ ์™”๋‹ค๋ฉด ๋‹ค๋ฆฌ์—์„œ ํƒˆ์ถœํ•œ๋‹ค
10+
* - ๋‹ค๋ฆฌ ์ตœ๋Œ€ํ•˜์ค‘ ์ดํ•˜์ผ๋•Œ๋งŒ ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ์— ์˜ฌ๋ผ์˜ฌ ์ˆ˜ ์žˆ๋‹ค
11+
* - ํ•œ๋ฒˆ์˜ ๋ฐ˜๋ณต์ด ์‹œ๊ฐ„ +1
12+
* ์ฐธ๊ณ : https://dy-coding.tistory.com/entry/%EB%B0%B1%EC%A4%80-13335%EB%B2%88-%ED%8A%B8%EB%9F%AD-java
13+
*/
14+
public class YJ_13335 {
15+
public static void main(String[] args) {
16+
Scanner sc =new Scanner(System.in);
17+
//n: ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋Š” ํŠธ๋Ÿญ์˜ ์ˆ˜, w: ๋‹ค๋ฆฌ์˜ ๊ธธ์ด, L: ๋‹ค๋ฆฌ์˜ ์ตœ๋Œ€ํ•˜์ค‘
18+
int N = sc.nextInt();
19+
int W = sc.nextInt();
20+
int L = sc.nextInt();
21+
22+
//ํŠธ๋Ÿญ๋ณ„ ์ด๋™ํ•ด์•ผ ํ•˜๋Š” ์ˆ˜ ์ €์žฅ๊ณต๊ฐ„
23+
int[] moveCount = new int[N];
24+
Queue<Truck> trucks = new LinkedList<>();
25+
for(int i=0; i<N; i++){
26+
trucks.offer(new Truck(i, sc.nextInt()));
27+
}
28+
29+
System.out.println(getMinTime(W, L, trucks, moveCount));
30+
}
31+
32+
static class Truck{
33+
int index;
34+
int weight;
35+
public Truck(int index,int weight){
36+
this.index = index;
37+
this.weight = weight;
38+
}
39+
}
40+
41+
static int getMinTime(int W, int L, Queue<Truck> trucks, int[] moveCount){
42+
Queue<Truck> bridge = new LinkedList<>();
43+
int time = 0;
44+
int bridgeWeight = 0;
45+
46+
while(!trucks.isEmpty()){ //์ตœ๋Œ€ N๋ฒˆ ๋ฐ˜๋ณต
47+
//๋‹ค๋ฆฌ์— ์˜ฌ๋ผ๊ฐˆ ์˜ˆ์ •์ธ ํŠธ๋Ÿญ
48+
Truck truck = trucks.peek();
49+
int idx = truck.index;
50+
int weight = truck.weight;
51+
52+
if(!bridge.isEmpty()){
53+
int start = bridge.peek().index; //โ˜…๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ๊ฐ€์žฅ ์•ž์— ์žˆ๋Š” ํŠธ๋Ÿญ์˜ ์ธ๋ฑ์Šค
54+
for(int i = start; i<idx; i++){ //O(logN)โ˜…์ƒˆ๋กœ ์˜ฌ๋ผ๊ฐ€๋ ค๋Š” ํŠธ๋Ÿญ์˜ ์ธ๋ฑ์Šค idx ์ „๊นŒ์ง€ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ๋“ค์ด ํ•œ ์นธ์”ฉ ์ „์ง„
55+
moveCount[i]--;
56+
}
57+
58+
if(moveCount[start] == 0) {
59+
bridgeWeight -= bridge.poll().weight;
60+
}
61+
}
62+
63+
//์˜ฌ๋ผ๊ฐ€๋ ค๋Š” ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ ํ•˜์ค‘ ๋ฌด๊ฒŒ๋ณด๋‹ค ํฌ์ง€ ์•Š์œผ๋ฉด ๋‹ค๋ฆฌ์— ์ž…์žฅ ๊ฐ€๋Šฅ
64+
if(bridgeWeight + weight<=L){
65+
bridge.offer(trucks.poll());
66+
bridgeWeight += weight;
67+
moveCount[idx] = W; //๊ฐ ํŠธ๋Ÿญ์€ ๋‹ค๋ฆฌ์˜ ๊ธธ์ด๋งŒํผ ์ด๋™ํ•œ๋‹ค
68+
}
69+
time++;
70+
}
71+
return time+W;
72+
}
73+
74+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜:
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: n์˜ ํฌ๊ธฐ 10^4 > O(n^2)๊นŒ์ง€ ๊ฐ€๋Šฅ
6+
* ์•„์ด๋””์–ด:
7+
* {1,2,3} ํ•œ์ •๋œ ์ˆซ์ž๋กœ n์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ๋ฐ˜๋ณต๋˜๋Š” ๊ทœ์น™์ด ์žˆ๋Š”์ง€ ํ™•์ธ
8+
*
9+
* n ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜ ์ฐพ๊ธฐ
10+
* ์ด๋•Œ 1์„ ์‹œ์ž‘์œผ๋กœ 1์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ฐพ์€ ํ›„ ๋‹ค์Œ ์ˆ˜๋กœ ์ด๋™. ์ˆœ์—ด ์ค‘๋ณต ๋ถˆ๊ฐ€
11+
* n=1 -> (1)
12+
* n=2 -> (1 1) (2)
13+
* n=3 -> (1 1 1) (1 2) (3)
14+
* n=4 -> (1 1 1 1) (1 1 2) (1 3) (2 2)
15+
* n=5 -> (1 1 1 1 1) (1 1 1 2) (1 2 2) (1 1 3) (2 3)
16+
*
17+
* ์ด๋•Œ ๊ฐ ๊ฒฝ์šฐ์˜ ๋งˆ์ง€๋ง‰ ์ˆ˜๊ฐ€ 1,2,3 ๊ฐ๊ฐ ๋ช‡๋ฒˆ ๋‚˜์˜ค๋Š”์ง€ ๊ฐฏ์ˆ˜๋ฅผ ์…Œ์„ ๋•Œ, ์ด ๊ฐฏ์ˆ˜์˜ ์ดํ•ฉ์ด ๋ฐฉ๋ฒ•์˜ ์ˆ˜๊ฐ€ ๋œ๋‹ค
18+
* n=1 -> 1:1๊ฐœ -> 1
19+
* n=2 -> 1:1๊ฐœ 2:1๊ฐœ -> 1+1= 2
20+
* n=3 -> 1:1๊ฐœ 2:1๊ฐœ 3:1๊ฐœ -> 1+1+1= 3
21+
* n=4 -> 1:1๊ฐœ 2:2๊ฐœ 3:1๊ฐœ -> 1+2+1= 4
22+
* n=5 -> 1:1๊ฐœ 2:2๊ฐœ 3:2๊ฐœ -> 1+2+2= 5
23+
* n=6 -> 1:1๊ฐœ 2:3๊ฐœ 3:3๊ฐœ -> 1+3+3= 5
24+
* n=7 -> 1:1๊ฐœ 2:3๊ฐœ 3:4๊ฐœ -> 1+3+4= 8
25+
*/
26+
public class YJ_15989 {
27+
public static void main(String[] args) {
28+
Scanner sc = new Scanner(System.in);
29+
int len = sc.nextInt();
30+
int[] testCase = new int[len];
31+
for(int i=0; i<len; i++){
32+
testCase[i]= sc.nextInt();
33+
}
34+
35+
int[][] dp = new int[10001][3];
36+
//1
37+
dp[0][0] = 1;
38+
//2
39+
dp[1][0] = 1;
40+
dp[1][1] = 1;
41+
//3
42+
dp[2][0] = 1;
43+
dp[2][1] = 1;
44+
dp[2][2] = 1;
45+
46+
for(int i=3; i<dp.length; i++){
47+
dp[i][0] = dp[i-1][0];
48+
dp[i][1] = dp[i-2][0] + dp[i-2][1];
49+
dp[i][2] = dp[i-3][0] + dp[i-3][1] + dp[i-3][2];
50+
}
51+
52+
for(int test : testCase){
53+
test = test-1;
54+
System.out.println(dp[test][0] + dp[test][1] + dp[test][2]);
55+
}
56+
}
57+
58+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.util.*;
2+
3+
/**
4+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: bfs
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: 1 โ‰ค N โ‰ค 500 ์ฒด์ŠคํŒ์˜ ํฌ๊ธฐ๋Š” N*N ์œผ๋กœ ์ตœ๋Œ€ 2500. O(N^2)๊นŒ์ง€ ๊ฐ€๋Šฅ
6+
* ์•„์ด๋””์–ด:
7+
* ๋‚˜์ดํŠธ(K)๋Š” 8๋ฐฉํ–ฅ์œผ๋กœ ์›€์ง์ผ ์ˆ˜ ์žˆ๊ณ , ๋ง์„ ์žก๊ธฐ ์œ„ํ•œ ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ > BFS ์•Œ๊ณ ๋ฆฌ์ฆ˜
8+
* ๊ฐ 8๋ฐฉํ–ฅ์„ ์›€์ง์ด๋Š”๋ฐ, ํ˜„์žฌ ์œ„์น˜ ~ ๋‹ค์Œ ์œ„์น˜๊นŒ์ง€ `์ด๋™ํ•œ ๊ฑฐ๋ฆฌ๋ฅผ ๊ฐ ์œ„์น˜๋งˆ๋‹ค ์ €์žฅ` `์ฒด์ŠคํŒ์—๋„ ์ด๋™๊ฑฐ๋ฆฌ ์ €์žฅ`
9+
* ์ฒด์ŠคํŒ์˜ ์œ„์น˜๋งˆ๋‹ค ์ด๋™ํ•œ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์†ํ•ด์„œ ๋ˆ„์ ํ•ด์„œ ์ €์žฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ (E)์ด ์žˆ๋Š” ์œ„์น˜๊ฐ€ ์ตœ๋‹จ๊ฑฐ๋ฆฌ๊ฐ€ ๋จ
10+
*/
11+
public class YJ_18404 {
12+
static class Knight{
13+
int x;
14+
int y;
15+
int distance;
16+
Knight(int x, int y, int distance){
17+
this.x = x;
18+
this.y = y;
19+
this.distance = distance;
20+
}
21+
}
22+
23+
static Queue<Knight> queue = new LinkedList<>();
24+
static int[][] MOVEMENTS = {{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};
25+
static void findMinMoveCount(int[][] chessBoard, boolean[][] visited) {
26+
while(!queue.isEmpty()){
27+
Knight knight = queue.poll();
28+
29+
for(int[] move : MOVEMENTS){
30+
int nextX = knight.x + move[0];
31+
int nextY = knight.y + move[1];
32+
33+
//์ด๋™ํ•  ์œ„์น˜์— ๋‚˜์ดํŠธ๊ฐ€ ๊ฐˆ ์ˆ˜ ์—†๋‹ค๋ฉด ํ•ด๋‹น ๊ตฌ๊ฐ„ ํƒ์ƒ‰ x
34+
if(nextX<1 || nextX >= chessBoard.length || nextY<1 || nextY >= chessBoard.length || visited[nextX][nextY]){
35+
continue;
36+
}
37+
38+
visited[nextX][nextY] = true;
39+
//๋‹ค์Œ ์œ„์น˜๋กœ ๊ฐˆ ๋‚˜์ดํŠธ์—๊ฒŒ ํ˜„์žฌ ์œ„์น˜~๋‹ค์Œ ์œ„์น˜๊นŒ์ง€์˜ ์ด๋™๊ฑฐ๋ฆฌ ๋ˆ„์  ์ €์žฅ
40+
int distance = knight.distance + 1;
41+
queue.offer(new Knight(nextX, nextY, distance));
42+
chessBoard[nextX][nextY] = distance;
43+
}
44+
}
45+
}
46+
47+
public static void main(String[] args) {
48+
Scanner sc = new Scanner(System.in);;
49+
//NxN:์ฒด์ŠคํŒ, M:๋ง ๊ฐฏ์ˆ˜
50+
String[] first = sc.nextLine().split(" ");
51+
int N = Integer.parseInt(first[0]);
52+
int M = Integer.parseInt(first[1]);
53+
54+
int[][] chessBoard = new int[N+1][N+1];
55+
boolean[][] visited = new boolean[N+1][N+1];
56+
57+
//๋‚˜์ดํŠธ์œ„์น˜
58+
String[] second = sc.nextLine().split(" ");
59+
int x =Integer.parseInt(second[0]);
60+
int y =Integer.parseInt(second[1]);
61+
queue.offer(new Knight(x,y,0));
62+
visited[x][y] = true;
63+
64+
//๋ง๋“ค ์œ„์น˜ ์ €์žฅ
65+
List<int[]> enemys = new ArrayList<>();
66+
for(int i=0; i<M; i++){
67+
String[] line = sc.nextLine().split(" ");
68+
int enemyX = Integer.parseInt(line[0]);
69+
int enemyY = Integer.parseInt(line[1]);
70+
enemys.add(new int[]{enemyX,enemyY});
71+
}
72+
73+
findMinMoveCount(chessBoard, visited);
74+
for(int[] e : enemys){
75+
System.out.print(chessBoard[e[0]][e[1]] + " ");
76+
}
77+
}
78+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/**
5+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: dfs
6+
* ์‹œ๊ฐ„๋ณต์žก๋„: 1 โ‰ค h โ‰ค 30 ํฌ๊ธฐ๋กœ bfs ์‚ฌ์šฉ๊ฐ€๋Šฅ
7+
* ์•„์ด๋””์–ด:
8+
* https://github.com/GreatAlgorithm-Study/AlgorithmStudy/issues/23
9+
*/
10+
public class YJ_๋””๋ฒ„๊น… {
11+
static final int MAX_N = 10;
12+
static final int MAX_H = 30;
13+
14+
static boolean[][] sadari = new boolean[MAX_H+1][MAX_N+1];
15+
static List<Connection> possibility = new ArrayList<>();
16+
static int MIN = Integer.MAX_VALUE;
17+
18+
public static void main(String[] args) throws IOException {
19+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
20+
//๊ณ ๊ฐ์˜ ์ˆ˜ n, ๋ฉ”๋ชจ๋ฆฌ ์œ ์‹ค ์„ ์˜ ๊ฐœ์ˆ˜ m, ์ทจ์•ฝ ์ง€์ ์˜ ๊ฐœ์ˆ˜ h
21+
String[] first = br.readLine().split(" ");
22+
int n = Integer.parseInt(first[0]);
23+
int m = Integer.parseInt(first[1]);
24+
int h = Integer.parseInt(first[2]);
25+
26+
//์‚ฌ๋‹ค๋ฆฌ ์ทจ์•ฝ์  ํ‘œ์‹œ
27+
for(int i=1; i<=m; i++){
28+
String[] next = br.readLine().split(" ");
29+
int number = Integer.parseInt(next[0]);
30+
int memory = Integer.parseInt(next[1]);
31+
sadari[number][memory] = true;
32+
}
33+
34+
//์ถ”๊ฐ€ ๊ฐ€๋Šฅํ•œ ์œ ์‹ค์„  ์ƒ์„ฑ
35+
for(int i=1; i<=h; i++){
36+
for(int j=1; j<n; j++){
37+
if(!sadari[i][j]){
38+
possibility.add(new Connection(i,j));
39+
}
40+
}
41+
}
42+
43+
findMinConnection(0,0,h,n);
44+
//์—ฐ๊ฒฐ๊ฐ€๋Šฅํ•œ ์œ ์‹ค์„ ์ด ์—†์„ ๊ฒฝ์šฐ
45+
if(MIN == Integer.MAX_VALUE){
46+
MIN = -1;
47+
}
48+
System.out.print(MIN);
49+
}
50+
51+
static class Connection {
52+
int a;
53+
int b;
54+
55+
public Connection(int a, int b){
56+
this.a = a;
57+
this.b = b;
58+
}
59+
}
60+
61+
//current(=i):์—ฐ๊ฒฐ๊ฐ€๋Šฅํ•œ ์œ ์‹ค์„ ๋งŒํผ ์ˆœํšŒ ,count:์ถ”๊ฐ€ํ•œ ์œ ์‹ค์„  ๊ฐฏ์ˆ˜
62+
static void findMinConnection(int current, int count, int h, int n){
63+
//์ถ”๊ฐ€ํ•œ ์œ ์‹ค์„ ์˜ ์ˆ˜๊ฐ€ ์ง€๊ธˆ๊นŒ์ง€ ๊ตฌํ•œ ๋‹ต๋ณด๋‹ค ์ข‹์•„์งˆ ์ˆ˜ ์—†๋‹ค๋ฉด?? โ˜…๋” ์ข‹์•„์ง„๋‹ค๋Š” ๊ธฐ์ค€์ด ๋ญ์ง€?
64+
if(count >= MIN){
65+
return;
66+
}
67+
68+
//์ตœ์ดˆ ๋˜๋Š” ์žฌ๊ท€ํ˜ธ์ถœ๋กœ ์—ฐ๊ฒฐ๋œ ์œ ์‹ค์„ ์ด ์ œ๋Œ€๋กœ ์‚ฌ๋‹ค๋ฆฌ๋ฅผ ํƒ€๋Š”์ง€ ํ™•์ธ
69+
if(isConnected(h,n)){
70+
MIN = Math.min(MIN,count);
71+
}
72+
73+
//๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ์ธ ์œ ์‹ค์„ ์˜ ๊ฐฏ์ˆ˜ ์ตœ๋Œ€ 3
74+
//ํ˜„์žฌ ์ˆœํšŒํ•˜๋Š” ์ธ๋ฑ์Šค๊ฐ€ ์—ฐ๊ฒฐ ๊ฐ€๋Šฅํ•œ ์œ ์‹ค์„ ์„ ๋ชจ๋‘ ์ˆœํšŒํ•˜๋ฉด ๋” ์ด์ƒ ์œ ์‹ค์„ ์ด ์—†์Œ
75+
if(count == 3 || current == possibility.size()){
76+
return;
77+
}
78+
79+
//์—ฐ๊ฒฐ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์œ ์‹ค์„ ์„ ์žฌ๊ท€ํ˜ธ์ถœ > โ˜…์ด๊ฑธ ์™œ ํ•˜์ง€?
80+
findMinConnection(current+1, count, h,n);
81+
//current == possibility.size()๋กœ ์ธํ•ด return ๋˜์–ด ์žฌ๊ท€ํ˜ธ์ถœ๋œ ์Šคํƒ์„ ํ•˜๋‚˜์”ฉ ๋ฐ˜ํ™˜
82+
83+
//์—ฐ๊ฒฐ ๊ฐ€๋Šฅํ•œ ์œ ์‹ค์„  ๊ฐ€์ ธ์˜ค๊ธฐ(๋งˆ์ง€๋ง‰๋ถ€ํ„ฐ ๊ฐ€์ ธ์˜ด)
84+
int a = possibility.get(current).a;
85+
int b = possibility.get(current).b;
86+
//์œ ์‹ค์„  ์—ฐ๊ฒฐ์ฒ˜๋ฆฌ
87+
sadari[a][b] = true;
88+
//์—ฐ๊ฒฐํ•œ ์œ ์‹ค์„ ์ด ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š”์ง€ ์žฌ๊ท€ํ˜ธ์ถœ
89+
findMinConnection(current+1, count+1, h,n);
90+
sadari[a][b] = false;
91+
}
92+
93+
//๋ฒˆํ˜ธ๋ณ„ ์‚ฌ๋‹ค๋ฆฌ ์ค„
94+
static int[] nums = new int[MAX_N+1];
95+
96+
//๋ชจ๋“  ์‚ฌ๋‹ค๋ฆฌ ์ค„์„ ์ˆœํšŒํ•˜๋ฉฐ i๋ฒˆ-i๊ณ ๊ฐ ์—ฐ๊ฒฐ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธ
97+
private static boolean isConnected (int h, int n){
98+
//์œ ์‹ค์„ ์ด ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์œผ๋ฉด ๋ฒ„๊ทธ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ถˆ๊ฐ€๋Šฅ
99+
for(int a=1; a<=h; a++){
100+
for(int b=2; b<n; b++){ //b๊ฐ€ 2๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ์ด์œ ? b=1๋กœ ํ•˜๋ฉด n+1 ๋ถˆํ•„์š”ํ•œ ๋ฒ”์œ„๊นŒ์ง€ ํ™•์ธํ•˜๊ธฐ ๋•Œ๋ฌธ
101+
if(sadari[a][b] && sadari[a][b-1]){
102+
return false;
103+
}
104+
}
105+
}
106+
107+
//์‚ฌ๋‹ค๋ฆฌ ๋ฒˆํ˜ธ ์ง€์ •
108+
for(int i=1; i<= n; i++){
109+
nums[i] = i;
110+
}
111+
112+
//์‚ฌ๋‹ค๋ฆฌ ํƒ€๋Š” ๋ฐฉ๋ฒ•: ์—ฐ๊ฒฐ์ง€์  ๋ผ๋ฆฌ ๋ฒˆํ˜ธ๋ฅผ ์„œ๋กœ ๊ตํ™˜
113+
for(int a=1; a<=h; a++) {
114+
for (int b = 1; b < n; b++) {
115+
if(sadari[a][b]){
116+
int exchange = nums[b];
117+
nums[b] = nums[b+1];
118+
nums[b+1] = exchange;
119+
}
120+
}
121+
}
122+
123+
//์‚ฌ๋‹ค๋ฆฌํƒ€๊ธฐ ์ข…๋ฃŒ ๊ฒ€์ฆ: i๋ฒˆ-i๊ณ ๊ฐ ์ผ์น˜
124+
for(int i=1; i<=n; i++){
125+
if(nums[i] != i){
126+
return false;
127+
}
128+
}
129+
return true;
130+
}
131+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- https://school.programmers.co.kr/learn/courses/30/lessons/301649
2+
-- ๋Œ€์žฅ๊ท  ๊ฐœ์ฒด์˜ ํฌ๊ธฐ์— ๋Œ€ํ•œ ์ˆœ์œ„
3+
-- ์ƒ์œ„ 0% ~ 25%:'CRITICAL', 26% ~ 50%:'HIGH', 51% ~ 75%:'MEDIUM', 76% ~ 100%:'LOW' ๋ถ„๋ฅ˜
4+
WITH ECOLI_PERCENT AS (
5+
SELECT
6+
ID,
7+
SIZE_OF_COLONY,
8+
PERCENT_RANK() OVER (ORDER BY SIZE_OF_COLONY DESC)*100 AS C_PERCENT
9+
FROM ECOLI_DATA
10+
)
11+
SELECT
12+
ID,
13+
CASE
14+
WHEN C_PERCENT <= 25 THEN 'CRITICAL'
15+
WHEN C_PERCENT <= 50 THEN 'HIGH'
16+
WHEN C_PERCENT <= 75 THEN 'MEDIUM'
17+
ELSE 'LOW'
18+
END AS COLONY_NAME
19+
FROM ECOLI_PERCENT
20+
ORDER BY ID;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- https://school.programmers.co.kr/learn/courses/30/lessons/151137
2+
-- 'ํ†ตํ’์‹œํŠธ', '์—ด์„ ์‹œํŠธ', '๊ฐ€์ฃฝ์‹œํŠธ' ์ค‘ ํ•˜๋‚˜ ์ด์ƒ์˜ ์˜ต์…˜์ด ํฌํ•จ๋œ ์ž๋™์ฐจ๊ฐ€ ์ž๋™์ฐจ ์ข…๋ฅ˜ ๋ณ„๋กœ ๋ช‡ ๋Œ€์ธ์ง€
3+
-- ์ž๋™์ฐจ ์ข…๋ฅ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
4+
SELECT
5+
CAR_TYPE
6+
,COUNT(*) AS CARS
7+
FROM CAR_RENTAL_COMPANY_CAR
8+
WHERE OPTIONS LIKE '%ํ†ตํ’์‹œํŠธ%'
9+
OR OPTIONS LIKE '%์—ด์„ ์‹œํŠธ%'
10+
OR OPTIONS LIKE '%๊ฐ€์ฃฝ์‹œํŠธ%'
11+
GROUP BY CAR_TYPE
12+
ORDER BY CAR_TYPE;

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /