Skip to content

Commit aaeef5a

Browse files
authored
Merge pull request #6 from yeahdy/main
[1์ฃผ์ฐจ] ์ด์˜ˆ์ง„
2 parents 14f4875 + e9618f2 commit aaeef5a

8 files changed

+340
-0
lines changed
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.util.*;
2+
3+
/**
4+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: ํˆฌ ํฌ์ธํ„ฐ
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
6+
* ์•„์ด๋””์–ด:
7+
* ์ฒ˜์Œ ์ ‘์‹œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์ ‘์‹œ๊นŒ์ง€์˜ ํ•˜๋‚˜์˜ ํšŒ์ „์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ N-1๋ฒˆ ํšŒ์ „์ด ํ•„์š”
8+
* ์ฒ˜์Œ ์ ‘์‹œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์ ‘์‹œ๊นŒ์ง€์˜ ์ด์–ด์ง„ k ๊ฐœ์˜ ์—ฐ์†๋œ ๋ฌถ์Œ์„ ๊ณ ๋ คํ–ˆ์„ ๋•Œ ํšŸ์ˆ˜๊ฐ€ N-1 ๋ฒˆ ํšŒ์ „ํ•˜๊ธฐ ๋•Œ๋ฌธ
9+
* N = 5, k = 3์ธ ๊ฒฝ์šฐ
10+
* 1 2
11+
* 0 3
12+
* 4
13+
* ์ดˆ๊ธฐ ์…‹ํŒ…: [0, 1, 2]
14+
* 1๋ฒˆ์งธ ์ด๋™: [1, 2, 3]
15+
* 2๋ฒˆ์งธ ์ด๋™: [2, 3, 4]
16+
* 3๋ฒˆ์งธ ์ด๋™: [3, 4, 0]
17+
* 4๋ฒˆ์งธ ์ด๋™: [4, 0, 1]
18+
*
19+
* ํšŒ์ „์„ ๋ฐ˜๋ณตํ•  ๋•Œ๋Š” ์ฒ˜์Œ๊ณผ ๋์„ index๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•˜๋‚˜์˜ k ๋กœ ๋ฌถ์–ด์„œ ํ™•์ธํ•ด์•ผํ•จ
20+
*/
21+
public class YJ_2531 {
22+
public static void main(String[] args) {
23+
Scanner sc = new Scanner(System.in);
24+
String[] first = sc.nextLine().split("\\s");
25+
26+
int N = Integer.parseInt(first[0]); //์ ‘์‹œ์˜ ์ˆ˜
27+
int d = Integer.parseInt(first[1]); //์ดˆ๋ฐฅ์˜ ๊ฐ€์ง“์ˆ˜
28+
int k = Integer.parseInt(first[2]); //์—ฐ์†ํ•ด์„œ ๋จน๋Š” ์ ‘์‹œ์˜ ์ˆ˜
29+
int c = Integer.parseInt(first[3]); //์ฟ ํฐ๋ฒˆํ˜ธ(=์ดˆ๋ฐฅ์ข…๋ฅ˜)
30+
31+
int[] belt = new int[N];
32+
for(int i = 0 ; i < N ; i++) {
33+
belt[i] = Integer.parseInt(sc.nextLine());
34+
}
35+
System.out.println(susiBelt(belt,N,d,k,c));
36+
}
37+
38+
static int susiBelt(int[] belt, int N, int d, int k, int c){
39+
int[] susi = new int[d+1]; //๋จน์€ ์ดˆ๋ฐฅ ์ข…๋ฅ˜ ๊ด€๋ จ ๋ฐฐ์—ด
40+
susi[c] = 3001; //๋ฌด๋ฃŒ ์ดˆ๋ฐฅ ์ข…๋ฅ˜(์ตœ๋Œ€ 3000)
41+
42+
int free = 1;
43+
for(int i=0;i<k;i++){ //์ดˆ๊ธฐ์…‹ํŒ…: ํšŒ์ „์ดˆ๋ฐฅ์„ ์ˆœํšŒํ•˜๋ฉฐ ๋‹ค๋ฅธ ์ข…๋ฅ˜์˜ k ๊ฐœ์˜ ์ดˆ๋ฐฅ ๋‹ด๊ธฐ
44+
int idx = belt[i];
45+
if(susi[idx]==0) //โ˜…belt[i]๋ฅผ ์Šค์‹œ์— ๋„ฃ์–ด์„œ ํšŒ์ „์ดˆ๋ฐฅ์—์„œ ์ค‘๋ณต๋œ ์ดˆ๋ฐฅ ์ข…๋ฅ˜๋ฅผ ๊ณตํ†ต์ ์œผ๋กœ ์ฒ˜๋ฆฌ
46+
free++;
47+
susi[idx]++;
48+
}
49+
50+
//โ˜…susi[i] ๊ฐ€ 1์ผ ๊ฒฝ์šฐ ์ด๋ฏธ ๋จน์Œ, 0์ผ ๊ฒฝ์šฐ ์ด๋ฏธ ๋จน์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ œ์™ธ์‹œํ‚ด
51+
int max = free;
52+
for(int i = 0; i < N-1; i++) { //O(n)
53+
int start = belt[i];
54+
int end = belt[((i+k) < N) ? (i+k) : (i+k) % N]; //โ˜…์กฐํ•ฉ ๋ฌถ์Œ +1 (== ๋งˆ์ง€๋ง‰ ์ ‘์‹œ > ์ฒ˜์Œ์ ‘์‹œ ํšŒ์ „)
55+
56+
// ์กฐํ•ฉ ๋ฌถ์Œ +1๋ฒˆ์งธ ์ดˆ๋ฐฅ์„ ์ฒ˜์Œ ๋จน์„ ๊ฒฝ์šฐ
57+
if(++susi[end] == 1){
58+
free++;
59+
}
60+
// ์ด๋ฏธ ๋จน์€ ์ดˆ๋ฐฅ ์ œ์™ธ
61+
if(--susi[start] == 0){
62+
free--;
63+
}
64+
max = Math.max(max, free);
65+
}
66+
return max;
67+
}
68+
69+
}
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/**
5+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: ์ด๋ถ„ํƒ์ƒ‰
6+
* ์‹œ๊ฐ„๋ณต์žก๋„: O(NlogN)
7+
* ์•„์ด๋””์–ด:
8+
* ์ˆœ์„œ๊ฐ€ ์ƒ๊ด€์—†๋‹ค๋ฉด ์ •๋ ฌ์„ ํ™œ์šฉํ•˜์ž > ์ด๋ถ„ํƒ์ƒ‰ ๊ฐ€๋Šฅ
9+
* ์ด๋ถ„ํƒ์ƒ‰ ์‚ฌ์šฉ๊ฐ€๋Šฅ ๋ฐฉ๋ฒ•: ์œ„ ์•„๋ž˜ ๊ฐ๊ฐ ๊ตฌ๋ถ„ํ•ด์„œ ๋™์‹œ์— ์ „์ฒด๋ฅผ ํƒ์ƒ‰ํ•˜๊ธฐ
10+
*/
11+
public class YJ_3020 {
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
String[] first = br.readLine().split("\\s");
15+
int N = Integer.parseInt(first[0]); //๋™๊ตด๊ธธ์ด
16+
int H = Integer.parseInt(first[1]); //๋†’์ด
17+
18+
int[] up = new int[N/2];
19+
int[] down = new int[N/2];
20+
for(int i=0; i<N/2; i++){
21+
int downNum = Integer.parseInt(br.readLine());
22+
int upNum = Integer.parseInt(br.readLine());
23+
down[i] = downNum;
24+
up[i] = upNum;
25+
}
26+
27+
System.out.println(destruction(N,H,up,down));
28+
}
29+
30+
static String destruction (int N, int H, int[] up, int[] down){
31+
int minDestroy = N; //์ดˆ๊ธฐ๊ฐ’์€ ์ตœ๋Œ€๊ฐ’์œผ๋กœ ์„ค์ •
32+
int spaceConut = 0;
33+
34+
Arrays.sort(up); //O(NlogN)
35+
Arrays.sort(down);
36+
37+
for(int i=1; i<H+1; i++){ //O(H)
38+
int destroy = binary(0,N/2,i,down) //โ˜…์‹œ์ž‘,๋,์ฒ˜์Œ๋†’์ด,์•„๋ž˜์žฅ์• ๋ฌผ
39+
+ binary(0,N/2,H-i+1,up); //โ˜…์‹œ์ž‘,๋,๋งˆ์ง€๋ง‰๋†’์ด,์œ„์žฅ์• ๋ฌผ
40+
41+
//์ตœ์†Œ ๊ตฌ๊ฐ„ ์นด์šดํŒ…
42+
if(destroy == minDestroy){
43+
spaceConut++;
44+
continue;
45+
}
46+
//ํŒŒ๊ดดํ•œ ์ตœ์†Œ๊ฐ’ ๊ฐฑ์‹ 
47+
if(destroy < minDestroy) {
48+
minDestroy = destroy;
49+
spaceConut = 1;
50+
}
51+
}
52+
return minDestroy + " " + spaceConut;
53+
}
54+
55+
//down H: 1 2 3 4 5 6 7
56+
//up H: 7 6 5 4 3 2 1
57+
private static int binary(int left, int right, int current, int[] cave){ //O(logN)
58+
//์ฐพ๋Š” ๊ฐ’(H)์ด ์ค‘๊ฐ„ ๋ณด๋‹ค ํด๊ฒฝ์šฐ ์ค‘๊ฐ„ ์ดํ•˜(์™ผ์ชฝ)์˜ ๊ฐ’๋“ค ๋ณด๋‹ค ๋ฌด์กฐ๊ฑด ํผ
59+
while(left < right){
60+
int mid = (left + right)/2;
61+
if(cave[mid] >= current){ //โ˜…์ถฉ๋Œ
62+
right = mid; //์™ผ์ชฝ์œผ๋กœ ์ด๋™
63+
} else {
64+
left = mid + 1; //์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™
65+
}
66+
}
67+
return cave.length-right; //์ถฉ๋Œ ์ˆ˜
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.Stack;
2+
3+
/**
4+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: Stack
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
6+
* ์•„์ด๋””์–ด:
7+
* ์ „์ฒด์—์„œ ํ•˜๋‚˜์”ฉ ๋” ํฐ์ˆ˜๋ฅผ ์ฐพ์œผ๋ฉฐ ๋น„๊ตํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ,
8+
* ์ „์ฒด ๋ฐ˜๋ณต์„ ๋Œ๋ฉด์„œ ๊ธฐ์กด ์ˆ˜๊ณผ ๋‹ค์Œ์— ์˜ค๋Š” ์ˆ˜๋ฅผ ๊ณ„์†ํ•ด์„œ ๋น„๊ตํ•˜๋Š”๋ฐ ์ด๋•Œ ์ด์ „์— ๋ˆ„์ ๋œ ์ˆ˜๋„ ํ•จ๊ป˜ ๊ฐฑ์‹ ํ•  ์ˆ˜ ์žˆ์–ด์•ผํ•œ๋‹ค.
9+
* ๋˜ํ•œ ๋ฐฐ์—ด์— ๋‹ด๊ธด ์ˆ˜๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด index ๋ฅผ ํ™œ์šฉํ•ด์„œ Stack์— index๋ฅผ ๋‹ด๊ณ  ์ด์ „์— ๋ˆ„์ ๋œ ์ˆ˜๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ํ•œ๋‹ค
10+
*/
11+
public class YJ_๋’ค์—_์žˆ๋Š”_ํฐ_์ˆ˜_์ฐพ๊ธฐ {
12+
public static void main(String[] args) {
13+
int[] numbers1 = {2, 3, 3, 5}; //3, 5, 5, -1
14+
int[] numbers2 = {9, 1, 5, 3, 6, 2}; //-1, 5, 6, 6, -1, -1
15+
int[] result = solution(numbers2);
16+
for (int j : result) {
17+
System.out.print(j + " ");
18+
}
19+
}
20+
21+
static int[] solution(int[] numbers) {
22+
int n = numbers.length;
23+
24+
Stack<Integer> stack = new Stack<>();
25+
int i = 0;
26+
stack.push(i);
27+
for(i=1; i<n; i++){ //O(n)
28+
while(!stack.isEmpty() && numbers[stack.peek()] < numbers[i]){ //O(n)
29+
numbers[stack.pop()] = numbers[i];
30+
}
31+
stack.push(i);
32+
}
33+
34+
while(!stack.isEmpty()){ //O(n)
35+
numbers[stack.pop()] = -1;
36+
}
37+
38+
return numbers;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.HashSet;
2+
3+
/**
4+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: HashSet
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
6+
* ์•„์ด๋””์–ด:
7+
* ์ „์ฒด ํ† ํ•‘ ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ฒ ์ˆ˜์™€ ๋™์ƒ์ด ๊ฐ๊ฐ ํ† ํ•‘์„ ๊ฐ€์ ธ๊ฐ„ ์ˆ˜๋ฅผ ์นด์šดํŒ…ํ–ˆ์„ ๋•Œ
8+
* ์ฒ ์ˆ˜(์™ผ์ชฝ) [1,2,2,3,3,4,4,4]
9+
* ๋™์ƒ(์˜ค๋ฅธ์ชฝ) [4,4,4,4,3,3,2,1]
10+
* ์ฒ ์ˆ˜๊ฐ€ ์™ผ์ชฝ์—์„œ ํ† ํ•‘ ํ•˜๋‚˜๋ฅผ ๊ฐ€์ ธ๊ฐ”์„ ๋•Œ ๋™์ƒ์€ ์˜ค๋ฅธ์ชฝ์„ ๊ธฐ์ค€์œผ๋กœ +1 ๊ฐœ๊นŒ์ง€๋งŒ ํ† ํ•‘์„ ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค
11+
* (๋™์ƒ์˜ ํ† ํ•‘์ˆ˜๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด ์ •๋ ฌ์€ ๋’ค์—์„œ ๋ถ€ํ„ฐ ์ž๋ฆ„)
12+
* ๋”ฐ๋ผ์„œ n(์ฒ ์ˆ˜) == n+1(๋™์ƒ) ์ด ๊ฐ™์„ ๋•Œ ํ‰๋“ฑํ•˜๊ฒŒ ํ† ํ•‘์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค
13+
*/
14+
public class YJ_๋กค์ผ€์ดํฌ_์ž๋ฅด๊ธฐ {
15+
public static void main(String[] args) {
16+
int[] topping = {1, 2, 1, 3, 1, 4, 1, 2};
17+
System.out.println(solution(topping));
18+
}
19+
20+
static int solution(int[] topping) {
21+
int n = topping.length;
22+
HashSet<Integer> toppingSet = new HashSet<>(); //HashSet<ํ† ํ•‘๊ฐฏ์ˆ˜> ํ† ํ•‘ ์ค‘๋ณต์ œ๊ฑฐ
23+
24+
int[] left = new int[n];
25+
for(int i=0; i<n; i++){ //O(n)
26+
toppingSet.add(topping[i]);
27+
left[i] = toppingSet.size();
28+
}
29+
30+
toppingSet.clear();
31+
int[] right = new int[n];
32+
for(int i=left.length-1; i>=0; i--){ //O(n)
33+
toppingSet.add(topping[i]);
34+
right[i] = toppingSet.size();
35+
}
36+
37+
int answer = 0;
38+
for(int i=0; i<n-1; i++){ //O(n)
39+
if(left[i] == right[i+1]){
40+
answer++;
41+
}
42+
}
43+
return answer;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import java.util.LinkedList;
2+
import java.util.Queue;
3+
4+
/**
5+
* ์•Œ๊ณ ๋ฆฌ์ฆ˜: BFS
6+
* ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
7+
* ์•„์ด๋””์–ด:
8+
* BFS๋กœ ์ˆœํšŒํ• ๋•Œ ๋ฐฉ๋ฌธํ•œ ์ง€์ ์„ ๋ฐฉ๋ฌธ์ฒ˜๋ฆฌ ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ๋‹ค๋…€๊ฐ„ ๊ธธ์„ ๋ฐฉ๋ฌธ์ฒ˜๋ฆฌ ํ•ด์•ผ ํ•จ
9+
* ๋‹ค๋…€๊ฐ„ ๊ธธ์„ ํ‘œ์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•?
10+
*
11+
*/
12+
public class YJ_๋ฐฉ๋ฌธ๊ธธ์ด {
13+
public static void main(String[] args) {
14+
String dirs = "ULURRDLLU"; //7
15+
// String dirs = "LULLLLLLU"; //7
16+
System.out.println(solution(dirs));
17+
}
18+
19+
static int answer = 0;
20+
static int[][] direction = {{0,1},{0,-1},{-1,0},{1,0}}; //์ƒ,ํ•˜,์ขŒ,์šฐ
21+
static boolean[][] visited = new boolean[11][11];
22+
static Queue<int[]> queue = new LinkedList<>();
23+
static int solution(String dirs) {
24+
String[] input = dirs.split("");
25+
int[] start = {5,5};
26+
int[] end = {11,11};
27+
28+
//ํ˜„์žฌ์œ„์น˜ ๋ฐฉ๋ฌธ์ฒ˜๋ฆฌ
29+
queue.offer(start);
30+
visited[start[0]][start[1]] = true;
31+
32+
for(String i : input){
33+
switch(i){
34+
case "U":
35+
bfs(visited,direction[0]);
36+
break;
37+
case "D":
38+
bfs(visited,direction[1]);
39+
break;
40+
case "L":
41+
bfs(visited,direction[2]);
42+
break;
43+
case "R":
44+
bfs(visited,direction[3]);
45+
break;
46+
}
47+
}
48+
return answer;
49+
}
50+
51+
private static void bfs(boolean[][] visited, int[] direction){
52+
int[] current = queue.peek();
53+
//์œ„์น˜ ์ด๋™
54+
int nx = current[0] + direction[0];
55+
int ny = current[1] + direction[1];
56+
57+
if(nx < 0 || nx > visited[0].length -1 || ny < 0 || ny > visited.length-1){
58+
return;
59+
}
60+
if(visited[nx][ny]){
61+
return;
62+
}
63+
//๋ฐฉ๋ฌธ์ฒ˜๋ฆฌ
64+
queue.poll();
65+
visited[nx][ny] = true;
66+
//์ด๋™๊ฐ’ ๊ฐฑ์‹ 
67+
queue.offer(new int[]{nx,ny});
68+
answer++;
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import java.util.HashSet;
2+
3+
public class YJ_์•ผ๊ทผ์ง€์ˆ˜ {
4+
public static void main(String[] args) {
5+
int[] topping = {1, 2, 1, 3, 1, 4, 1, 2};
6+
System.out.println(solution(topping));
7+
}
8+
9+
static int solution(int[] topping) {
10+
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- ๋ฌธ์ œ: https://school.programmers.co.kr/learn/courses/30/lessons/276035
2+
-- ์š”๊ตฌ์‚ฌํ•ญ: ๊ฐœ๋ฐœ์ž์˜ ID, ์ด๋ฉ”์ผ, ์ด๋ฆ„, ์„ฑ์„ ์กฐํšŒ + ID๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
3+
4+
SELECT
5+
D.ID, D.EMAIL, D.FIRST_NAME, D.LAST_NAME
6+
FROM DEVELOPERS AS D
7+
INNER JOIN SKILLCODES AS S
8+
ON D.SKILL_CODE & S.CODE = S.CODE
9+
WHERE S.CATEGORY = 'Front End'
10+
GROUP BY D.ID, D.EMAIL, D.FIRST_NAME, D.LAST_NAME
11+
ORDER BY D.ID;
12+
13+
-- ์ฐธ๊ณ 
14+
-- ๋น„ํŠธ AND์—ฐ์‚ฐ (10์ง„์ˆ˜ & 10์ง„์ˆ˜)
15+
-- 400 & 16 (110010000 & 10000)
16+
-- ๊ฒฐ๊ณผ: 16 (10000)
17+
-- SQL์—์„œ ๋น„ํŠธ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๋ฅผ 2์ง„์ˆ˜๋กœ ์ž๋™๋ณ€ํ™˜ํ•ด์„œ ์—ฐ์‚ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณ€ํ™˜ํ•˜์ง€ ์•Š์•„๋„๋จ
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- ๋ฌธ์ œ: https://school.programmers.co.kr/learn/courses/30/lessons/133027
2+
-- ์š”๊ตฌ์‚ฌํ•ญ: ์ƒ์œ„ 3๊ฐœ FLAVOR ๋ง›๋ณ„๋กœ (7์›” ์•„์ด์Šคํฌ๋ฆผ ์ด ์ฃผ๋ฌธ๋Ÿ‰+์ƒ๋ฐ˜๊ธฐ์˜ ์•„์ด์Šคํฌ๋ฆผ ์ด ์ฃผ๋ฌธ๋Ÿ‰)
3+
SELECT
4+
JULY.FLAVOR
5+
FROM JULY
6+
INNER JOIN
7+
(SELECT
8+
FIRST_HALF.FLAVOR
9+
,FIRST_HALF.TOTAL_ORDER AS T_O
10+
FROM FIRST_HALF) AS FH
11+
ON JULY.FLAVOR = FH.FLAVOR
12+
GROUP BY FLAVOR
13+
ORDER BY SUM(JULY.TOTAL_ORDER+FH.T_O) DESC
14+
LIMIT 3;
15+
16+
-- ์ฐธ๊ณ 
17+
-- FIRST_HALF ํ…Œ์ด๋ธ” PK: FLAVOR, FK: SHIPMENT_ID
18+
-- JULY ํ…Œ์ด๋ธ” PK: SHIPMENT_ID FK: FLAVOR

0 commit comments

Comments
ย (0)