-
Notifications
You must be signed in to change notification settings - Fork 4
[1주차] 고다혜 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[1주차] 고다혜 #1
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
62c3fd0
고다혜: [CT] 자율주행 자동차_240909
KodaHye fb88751
고다혜: [CT] 불안한 무빙워크_240909
KodaHye 7233c1c
고다혜: [BOJ] 2531 회전 초밥_240910
KodaHye 6fb476e
고다혜: [SQL] Python 개발자 찾기_240910
KodaHye aba8381
고다혜: [BOJ] 3020 개똥벌레_240911
KodaHye b844295
고다혜: [SQL] 입양 시각 구하기(1)_240912
KodaHye 4e7ef3a
고다혜: [PG] 12927 야근 지수_240912
KodaHye ae53f0d
고다혜: [PG] 132265 롤케이크 자르기_240912
KodaHye 9ddb841
고다혜: [PG] 49994 방문 길이_240913
KodaHye 1076216
고다혜: [PG] 154539 뒤에 있는 큰 수 찾기_240913
KodaHye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
public class DH_2531 { | ||
static int N, d, k, c, arr[], eat[]; | ||
|
||
// 투포인터 | ||
// * 조건 | ||
// - s ~ e 거리가 k보다 작다면 e += 1 | ||
// - s ~ e 거리가 k보다 크거나 같다면 s += 1; | ||
// - s ~ e 거리가 k랑 같다면 초밥 종류의 개수 찾기 | ||
static void solution() { | ||
int s = 0, e = 0; | ||
int result = 0; | ||
|
||
eat[arr[s]]++; | ||
|
||
while(s <= e && s < N) { | ||
if(e - s + 1 < k) { | ||
e++; | ||
int tmpE = e % N; | ||
eat[arr[tmpE]]++; | ||
} else { | ||
eat[arr[s]]--; | ||
s++; | ||
} | ||
|
||
if(e - s + 1 == k) result = Math.max(result, getCnt()); | ||
} | ||
|
||
System.out.println(result); | ||
} | ||
|
||
static int getCnt() { | ||
int result = 0; | ||
for(int e: eat) { | ||
if(e == 0) continue; | ||
result += 1; | ||
} | ||
|
||
if(eat[c] == 0) result += 1; | ||
return result; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
N = read(); d = read(); k = read(); c = read(); | ||
|
||
arr = new int[N]; | ||
eat = new int[d + 1]; // 초밥의 가지수 | ||
|
||
for(int i = 0; i < N; i++) arr[i] = read(); | ||
|
||
solution(); | ||
} | ||
|
||
static int read() throws Exception { | ||
int c, n = System.in.read() & 15; | ||
while((c = System.in.read()) >= 48) | ||
n = (n << 3) + (n << 1) + (c & 15); | ||
return n; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import java.util.*; | ||
|
||
public class DH_3020 { | ||
// arr1: 석순, arr2: 종유석 | ||
static int N, H, min, cnt, arr1[], arr2[]; | ||
|
||
static void solution() { | ||
|
||
// 개똥벌레가 날아다니는 위치를 1부터 H까지 설정하면서 | ||
// 부딪히는 석순과 종유석의 개수를 구함 | ||
for(int i = 1; i < H + 1; i++) { | ||
// tmp: 높이가 i일 때, 개똥벌레가 부딪히는 (석순 + 종유석) 개수 | ||
int tmp = getCnt(arr1, i) + getCnt(arr2, H - i + 1); | ||
|
||
if(min == tmp) cnt++; | ||
else if(min > tmp) { | ||
min = tmp; | ||
cnt = 1; | ||
} | ||
} | ||
} | ||
|
||
// 정렬된 석순, 종유석에 대해 높이 기준 큰 것들의 개수 구함 (깨질 수 있는 높이) | ||
static int getCnt(int arr[], int height) { | ||
int s = 0, e = arr.length; | ||
|
||
while(s < e) { | ||
int m = (s + e) / 2; | ||
|
||
if(arr[m] >= height) e = m; | ||
else if(arr[m] < height) s = m + 1; | ||
} | ||
|
||
return arr.length - e; | ||
} | ||
public static void main(String[] args) throws Exception { | ||
N = read(); | ||
H = read(); | ||
|
||
arr1 = new int[N >> 1]; // 석순 | ||
arr2 = new int[N >> 1]; // 종유석 | ||
|
||
min = Integer.MAX_VALUE; | ||
|
||
for(int i = 0; i < N >> 1; i++) { | ||
int a = read(), b = read(); | ||
arr1[i] = a; arr2[i] = b; | ||
} | ||
|
||
// 석순과 종유석을 오름차순으로 정렬 | ||
Arrays.sort(arr1); | ||
Arrays.sort(arr2); | ||
|
||
solution(); | ||
System.out.print(min + " " + cnt); | ||
} | ||
|
||
|
||
static int read() throws Exception { | ||
// System.in.read(): 1byte 크기만 읽어 ASCII 코드에 해당하는 int 값 리턴 | ||
// n = System.in.read()일 때, 한글자의 수를 읽으면 48 <= n <58 | ||
int c, n = System.in.read() & 15; | ||
|
||
// ASCII 코드 48이상인 경우 (0-9의 숫자) | ||
while((c = System.in.read()) >= 48) | ||
n = (n << 3) + (n << 1) + (c & 15); | ||
if(c == 13) // 입력이 Enter일 경우 다음 바이트를 읽어 해당 문자 건너뛰기 | ||
System.in.read(); | ||
|
||
return n; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class DH_자율주행_자동차 { | ||
// 자동차의 위치, 바라보는 방향을 저장하는 클래스 | ||
static class Car { | ||
int r, c, d; | ||
public Car(int r, int c, int d) { | ||
this.r = r; | ||
this.c = c; | ||
this.d = d; | ||
} | ||
} | ||
static Car car; | ||
static int dr[] = {-1, 0, 1, 0}; | ||
static int dc[] = {0, 1, 0, -1}; | ||
// map: 도로와 자동차가 움직인 정보를 가지고 있음 | ||
// - 0: 갈 수 있는 도로, 1: 인도, 2: 이미 지나간 도로 | ||
// result: 자동차가 움직인 도롤의 총 면적 | ||
static int map[][], result = 1; | ||
|
||
static void solution() { | ||
map[car.r][car.c] = 2; | ||
|
||
while(true) { | ||
// 네 방향을 기준으로 왼쪽으로 갈 수 있는지 확인하하기 위한 변수 | ||
int cnt = 0; | ||
// 왼쪽으로 갈 수 있는지 확인 | ||
if(!canMoveLeft()) { | ||
// 자동차를 회전시키면서 왼쪽으로 갈 수 있는지 확인 | ||
while(cnt++ < 3) if(canMoveLeft()) break; | ||
|
||
// cnt가 4라면 모든 방향에 대해 확인해봤지만 갈 수 없는 상황 | ||
if(cnt == 4) { | ||
int nr = car.r - dr[car.d]; | ||
int nc = car.c - dc[car.d]; | ||
|
||
updateCarInfo(nr, nc, car.d); | ||
if(!check(nr, nc) || map[nr][nc] == 1) break; | ||
} | ||
} | ||
} | ||
|
||
System.out.println(result); | ||
} | ||
|
||
// 왼쪽으로 갈 수 있는지 확인 | ||
static boolean canMoveLeft() { | ||
int d = (car.d - 1 + 4) % 4; | ||
int nr = car.r + dr[d]; | ||
int nc = car.c + dc[d]; | ||
|
||
car.d = d; | ||
if(!check(nr, nc) || map[nr][nc] != 0) return false; | ||
updateCarInfo(nr, nc, d); | ||
map[nr][nc] = 2; | ||
result++; | ||
|
||
return true; | ||
} | ||
|
||
// 자동차의 정보 업데이트 | ||
static void updateCarInfo(int r, int c, int d) { | ||
car.r = r; | ||
car.c = c; | ||
car.d = d; | ||
} | ||
static boolean check(int r, int c) { | ||
return r >= 0 && r < map.length && c >= 0 && c < map[0].length; | ||
} | ||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int m = Integer.parseInt(st.nextToken()); | ||
map = new int[n][m]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
int cr = Integer.parseInt(st.nextToken()); | ||
int cc = Integer.parseInt(st.nextToken()); | ||
int cd = Integer.parseInt(st.nextToken()); | ||
|
||
car = new Car(cr, cc, cd); | ||
for(int r = 0; r < map.length; r++) { | ||
String s = br.readLine(); | ||
for(int c = 0; c < map[0].length; c++) { | ||
map[r][c] = s.charAt(c * 2) - '0'; | ||
} | ||
} | ||
|
||
solution(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class DH_불안한_무빙워크 { | ||
// cnt: 몇 번째 실험인지 저장하는 변수 | ||
// arr: 무빙워크의 안정성 | ||
static int cnt, N, K, arr[]; | ||
// v: 무빙워크에 사람이 있는지 확인 | ||
// 어짜피 [0][N - 1] 위치에 가면 사람은 무빙워크에서 내려가기 때문에 | ||
// arr의 0번째 행만 고려함 -> v: 1차원 배열 | ||
static boolean v[]; | ||
|
||
static void movePeople() { | ||
for (int i = N - 1; i > 0; i--) { | ||
if(!v[i]) continue; | ||
// 해당 칸에 사람이 있으면서 안정성이 0보다 크다면 | ||
// 사람 이동 | ||
if(v[i + 1] || arr[i + 1] == 0) continue; | ||
v[i + 1] = true; | ||
v[i] = false; | ||
arr[i + 1]--; | ||
|
||
if(arr[i + 1] == 0) cnt++; | ||
} | ||
} | ||
|
||
static void moveMovingWalk() { | ||
// 무빙워크 안정성 옆 칸으로 이동 | ||
arr[0] = arr[arr.length - 1]; | ||
for(int i = arr.length - 1; i > 0; i--) { | ||
arr[i] = arr[i - 1]; | ||
} | ||
|
||
// 무빙워크 이동할 떄, 무빙워크 위에 있는 사람도 같이 이동 | ||
for(int i = v.length - 2; i > 0; i--) v[i + 1] = v[i]; | ||
// N 위치에 가면 내림 | ||
v[N] = false; | ||
// 첫 번째도 사람이 없어야 됨 | ||
v[1] = false; | ||
} | ||
|
||
static void addPerson() { | ||
if(arr[1] == 0) return; | ||
v[1] = true; | ||
arr[1]--; | ||
if(arr[1] == 0) cnt++; | ||
} | ||
|
||
static void solution() { | ||
int turn = 0; | ||
|
||
while(true) { | ||
turn++; | ||
// 무빙워크 이동 | ||
moveMovingWalk(); | ||
// 사람 이동 | ||
movePeople(); | ||
// 처음 칸의 안정성 확인 이후 사람 추가 | ||
addPerson(); | ||
|
||
if(cnt >= K) break; | ||
} | ||
|
||
System.out.println(turn); | ||
} | ||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
arr = new int[2 * N + 1]; | ||
v = new boolean[N + 1]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for(int i = 1; i < arr.length; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
solution(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package Programmers.Level2; | ||
|
||
/* | ||
롤케이크_자르기 | ||
*/ | ||
|
||
class DH_132265 { | ||
|
||
public int solution(int[] topping) { | ||
int length = topping.length; | ||
int toppingType = 0, answer = 0; | ||
|
||
int cnt[] = new int[10_001]; | ||
for(int i = 0; i < length; i++) { | ||
if(cnt[topping[i]] == 0) toppingType++; | ||
cnt[topping[i]]++; | ||
} | ||
|
||
int cntA = 0; | ||
boolean check[] = new boolean[10_001]; | ||
|
||
for(int i = 0; i < length; i++) { | ||
if(!check[topping[i]]) { | ||
cntA++; | ||
check[topping[i]] = true; | ||
} | ||
|
||
cnt[topping[i]]--; | ||
if(cnt[topping[i]] == 0) toppingType--; | ||
if(cntA == toppingType) answer++; | ||
} | ||
return answer; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Programmers.Level2; | ||
import java.util.*; | ||
|
||
/* | ||
뒤에 있는 큰 수 찾기 | ||
*/ | ||
|
||
class DH_154539 { | ||
public int[] solution(int[] numbers) { | ||
|
||
int[] answer = new int[numbers.length]; | ||
Arrays.fill(answer, - 1); | ||
|
||
Stack<Integer> stack = new Stack(); | ||
for(int i = numbers.length - 1; i >= 0; i--) { | ||
|
||
if(!stack.isEmpty() && numbers[i] >= stack.peek()) { | ||
while(!stack.isEmpty() && numbers[i] >= stack.peek()) { | ||
stack.pop(); | ||
} | ||
} | ||
|
||
if(!stack.isEmpty()) answer[i] = stack.peek(); | ||
stack.push(numbers[i]); | ||
} | ||
|
||
return answer; | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굉장히 멋진 방법이네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다~