-
Notifications
You must be signed in to change notification settings - Fork 4
[16주차] 배수빈 #223
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
[16주차] 배수빈 #223
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b27405c
배수빈: [CT] 보도블럭_241230
baexxbin 12a6f6d
배수빈: [BOJ] 23326 홍익 투어리스트_250101
baexxbin ce239c1
배수빈: [SQL] Confirmation Rate_250101
baexxbin d2f98fd
배수빈: [BOJ] 20002 사과나무_250102
baexxbin 1b62c1d
배수빈: [PG] 131703 2차원 동전 뒤집기_250102
baexxbin 57364b5
배수빈: [BOJ] 2258 정육점_250103
baexxbin ff5c5e3
배수빈: [SQL] Nth Highest Salary_250103
baexxbin 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
52 changes: 52 additions & 0 deletions
BOJ/1000-5000번/SB_2258.java
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,52 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_2258 { | ||
static int N, M; | ||
static int[][] dp; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
dp = new int[N][2]; | ||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
dp[i][0] = Integer.parseInt(st.nextToken()); // 무게 | ||
dp[i][1] = Integer.parseInt(st.nextToken()); // 가격 | ||
} | ||
|
||
// 가격 오름차순, 무게 내림차순 | ||
Arrays.sort(dp, (o1, o2) -> { | ||
if (o1[1] != o2[1]) return o1[1] - o2[1]; | ||
return o2[0] - o1[0]; // 가격이 같을땐 무게 기준 내림차순 | ||
}); | ||
|
||
|
||
int total = 0; | ||
int price = 0; | ||
int mn = Integer.MAX_VALUE; | ||
boolean flag = false; | ||
|
||
for (int i = 0; i < N; i++) { | ||
total += dp[i][0]; // 무게 계속 누적 됨 | ||
|
||
if (i > 0 && dp[i-1][1] == dp[i][1]) // 같은 가격의 고기는 돈 지불 | ||
price += dp[i][1]; | ||
else price = dp[i][1]; // 다른 가격이면, 이 가격으로 지금까지 고기 다 살 수 있음(가격 오름차순 정렬) | ||
|
||
if (total >= M){ | ||
flag = true; | ||
mn = Math.min(mn, price); // 동일한 가격이 누적됐을때, 새로운 값이 더 쌀 수 있음 | ||
} | ||
} | ||
|
||
System.out.println(flag ? mn : -1); | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
BOJ/20001-25000번/SB_20002.java
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,40 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_20002 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
int[][] board = new int[N][N]; | ||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < N; j++) { | ||
board[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
int[][] dp = new int[N + 1][N + 1]; | ||
for (int i = 1; i <= N; i++) { // 누적합 | ||
for (int j = 1; j <= N; j++) { | ||
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + board[i - 1][j - 1]; | ||
} | ||
} | ||
|
||
int mx = Integer.MIN_VALUE; | ||
for (int k = 0; k < N; k++) { | ||
for (int i = 1; i < N - k + 1; i++) { | ||
for (int j = 1; j < N - k + 1; j++) { | ||
int box = dp[i+k][j+k]-dp[i-1][j+k]-dp[i+k][j-1]+dp[i-1][j-1]; | ||
mx = Math.max(mx, box); | ||
} | ||
} | ||
} | ||
|
||
System.out.println(mx); | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
BOJ/20001-25000번/SB_23326.java
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,53 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
import java.util.TreeSet; | ||
|
||
public class SB_23326 { | ||
static int N, Q; | ||
static TreeSet<Integer> place = new TreeSet<>(); | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
Q = Integer.parseInt(st.nextToken()); | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
if (Integer.parseInt(st.nextToken())==1) place.add(i); | ||
} | ||
|
||
int cur = 0; | ||
while (Q-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int cmd = Integer.parseInt(st.nextToken()); | ||
switch (cmd) { | ||
case 1: | ||
int p = Integer.parseInt(st.nextToken()) - 1; | ||
if (place.contains(p)) place.remove(p); | ||
else place.add(p); | ||
break; | ||
case 2: | ||
int val = Integer.parseInt(st.nextToken()); | ||
cur = (cur + val) % N; | ||
break; | ||
case 3: | ||
if (place.isEmpty()) sb.append(-1).append('\n'); | ||
else if (place.contains(cur)) sb.append(0).append('\n'); | ||
else { | ||
Integer right = place.higher(cur); | ||
if (right != null) sb.append(right - cur).append('\n'); | ||
else { | ||
Integer left = place.first(); | ||
sb.append(N - cur + left).append('\n'); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
System.out.println(sb); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
CodeTree/2017-2018년/SB_보도블럭.java
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,62 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
/* | ||
* 오름차순: 세어온 개수가 L이상이고 다음 높이랑 1차이나면 가능 | ||
* 내림차순: 이전값 pre, 이후 세는 개수가 L이상이고 pre랑 높이 1차이나면 가능 | ||
* */ | ||
public class SB_보도블럭 { | ||
static int N, L; | ||
static int[][] board; | ||
static int ans = 0; | ||
|
||
private static boolean canPass(int[] line) { | ||
boolean[] used = new boolean[N]; | ||
for (int i = 0; i < N - 1; i++) { | ||
if (line[i]==line[i+1]) continue; // 같은 높이 | ||
if (line[i+1]-line[i]==1) { // 오름차순 | ||
for (int j = 0; j < L; j++) { // 자기자신부터 경사로 설치 됨 | ||
if (i-j < 0 || line[i] != line[i-j] || used[i-j]) return false; | ||
used[i-j] = true; | ||
} | ||
} else if (line[i+1]-line[i]==-1) { // 내림차순 | ||
for (int j = 1; j <= L; j++) { // 자기 앞에부터 경사로 설치 | ||
if (i+j >=N || line[i+1] != line[i+j] || used[i+j]) return false; | ||
used[i+j] = true; | ||
} | ||
} else return false; // 높이차로 경사로 설치 불가 | ||
} | ||
return true; | ||
} | ||
Comment on lines
+15
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 배열 전체를 탐색하면서 전체 배열에 대해 총 몇 개의 도로가 가능한가를 구해줬는데요,, |
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
L = Integer.parseInt(st.nextToken()); | ||
|
||
board = new int[N][N]; | ||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < N; j++) { | ||
board[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
for (int[] row : board){ // 가로 확인 | ||
if (canPass(row)) ans++; | ||
} | ||
|
||
for (int j = 0; j < N; j++) { // 세로 확인 | ||
int[] col = new int[N]; | ||
for (int i = 0; i < N; i++) { | ||
col[i] = board[i][j]; | ||
} | ||
if (canPass(col)) ans++; | ||
} | ||
|
||
System.out.println(ans); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
Programmers/Level3/SB_131703.java
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,68 @@ | ||
public class SB_131703 { | ||
static int N, M; | ||
static int[][] tg; | ||
|
||
private static boolean isSame(int[][] board){ | ||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (board[i][j] != tg[i][j]) return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static void flipRow(int[][] board, int r) { // 행 뒤집기 | ||
for (int c = 0; c < M; c++) { | ||
board[r][c] ^= 1; | ||
} | ||
} | ||
private static void flipCol(int[][] board, int c) { // 열 뒤집기 | ||
for (int r = 0; r < N; r++) { | ||
board[r][c] ^= 1; | ||
} | ||
} | ||
|
||
private static int[][] copy(int[][] origin) { | ||
int[][] board = new int[N][M]; | ||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
board[i][j] = origin[i][j]; | ||
} | ||
} | ||
return board; | ||
} | ||
public static int solution(int[][] beginning, int[][] target) { | ||
N = target.length; | ||
M = target[0].length; | ||
tg = copy(target); | ||
|
||
int mn = Integer.MAX_VALUE; | ||
|
||
for (int rowMask = 0; rowMask < (1 << N); rowMask++) { // 모든 행의 뒤집기 조합 | ||
for (int colMask = 0; colMask < (1 << M); colMask++) { // 모든 열의 뒤집기 조합 | ||
int[][] tmp = copy(beginning); | ||
int flip = 0; | ||
|
||
// 뒤집기에 해당하는 행 찾기 | ||
for (int r = 0; r < N; r++) { | ||
if ((rowMask & (1<<r)) !=0){ | ||
flipRow(tmp, r); | ||
flip++; | ||
} | ||
} | ||
|
||
// 뒤집기에 해당하는 열 찾기 | ||
for (int c = 0; c < M; c++) { | ||
if ((colMask & (1 << c)) != 0) { | ||
flipCol(tmp, c); | ||
flip++; | ||
} | ||
} | ||
|
||
// 목표한 상태랑 일치하는지 체크 | ||
if (isSame(tmp)) mn = Math.min(mn, flip); | ||
} | ||
} | ||
return (mn==Integer.MAX_VALUE) ? -1 : mn; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
SQL/16주차/SB_Confirmation Rate.sql
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,8 @@ | ||
# Write your MySQL query statement below | ||
# 사용자의 확인율은 '확인'된 메시지의 수를 요청된 확인 메시지의 총 수로 나눈 값입니다. 확인 메시지를 요청하지 않은 사용자의 확인율은 0입니다. 확인율을 소수점 두 자리로 반올림합니다. | ||
|
||
SELECT s.user_id, | ||
ROUND(IFNULL(AVG(c.action="confirmed"),0),2) AS confirmation_rate | ||
FROM Signups s | ||
LEFT JOIN Confirmations c ON s.user_id = c.user_id | ||
GROUP BY s.user_id |
13 changes: 13 additions & 0 deletions
SQL/16주차/SB_Nth Highest Salary.sql
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,13 @@ | ||
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT | ||
BEGIN | ||
SET N = N-1; | ||
RETURN ( | ||
# Write your MySQL query statement below. | ||
# Employee 테이블에서 n번째로 큰 급여를 반환하는 query를 작성 | ||
# 만약에 n번째로 큰 급여 정보가 없다면, NULL을 반환 | ||
SELECT DISTINCT salary | ||
FROM Employee | ||
ORDER BY salary DESC | ||
LIMIT 1 OFFSET N | ||
); | ||
END |
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.