diff --git "a/BOJ/1000-5000\353\262\210/YJ_1194.java" "b/BOJ/1000-5000\353\262\210/YJ_1194.java" new file mode 100644 index 00000000..e95c81ab --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/YJ_1194.java" @@ -0,0 +1,100 @@ +import java.io.*; +import java.util.*; + +//bfs + 비트마스킹 +//처음에 dfs 로 접근했는데, 그럼 모든 경로를 다 탐색 해 버리더라구요 최단거리 문제는 bfs 로 풀기! +public class YJ_1194 { + static class Pos { + int x; + int y; + int distance; + int hasKey; + + public Pos(int x, int y, int distance, int hasKey) { + this.x = x; + this.y = y; + this.distance = distance; + this.hasKey = hasKey; + } + } + + static final char EXIT = '1'; + static final char CURRENT = '0'; + static final char WALL = '#'; + + static int N; + static int M; + static char[][] maze; + + 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()); + maze = new char[N][M]; + visited = new boolean[N][M][64]; //★키 6개 2^6 = 64 + + int x = 0; + int y = 0; + for(int i=0; i pq = new ArrayDeque<>(); + int[] dx = {0,1,0,-1}; + int[] dy = {1,0,-1,0}; + + pq.offer(new Pos(x,y,0,0)); + visited[x][y][0] = true; + + while(!pq.isEmpty()) { + Pos pos = pq.poll(); + if(maze[pos.x][pos.y] == EXIT) { + return pos.distance; + } + + for(int d=0; d<4; d++){ + int nx = pos.x + dx[d]; + int ny = pos.y + dy[d]; + if(stop(nx,ny, pos.hasKey)){ + continue; + } + + int key = pos.hasKey; + if(maze[nx][ny] >= 'A' && maze[nx][ny] <= 'F') { + if((key & 1<<(maze[nx][ny] - 'A')) > 0){ //가지고 있는 키와 일치하는 경우 (A=65) + visited[nx][ny][key] = true; + }else{ + continue; + } + }else if(maze[nx][ny] >= 'a' && maze[nx][ny] <= 'f'){ //키를 주운 경우 + key |= 1<<(maze[nx][ny] - 'a'); //a=97 + visited[nx][ny][key] = true; + }else{ + visited[nx][ny][key] = true; //'.' + } + + pq.offer(new Pos(nx,ny,pos.distance+1,key)); + } + } + + return -1; + } + + static private boolean stop(int x, int y, int hasKey){ + return x < 0 || x >= N || y < 0 || y >= M || maze[x][y] == WALL || visited[x][y][hasKey]; + } + +} \ No newline at end of file diff --git "a/BOJ/1000-5000\353\262\210/YJ_1749.java" "b/BOJ/1000-5000\353\262\210/YJ_1749.java" new file mode 100644 index 00000000..462d3e32 --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/YJ_1749.java" @@ -0,0 +1,37 @@ +import java.io.*; +import java.util.*; + +public class YJ_1749 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken())+1; + int M = Integer.parseInt(st.nextToken())+1; + int [][] game = new int[N][M]; + + for(int i = 1; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for(int j = 1; j < M; j++) { + game[i][j] = Integer.parseInt(st.nextToken()); + } + } + //누적합 + for(int i = 1; i < N; i++) { + for(int j = 1; j < M; j++) { + game[i][j] = game[i-1][j] + game[i][j-1] - game[i-1][j-1] + game[i][j]; + } + } + + int max = game[1][1]; + for(int i = 1; i < N; i++) { + for(int j = 1; j < M; j++) { + for(int r = 0; r < i; r++) { + for(int k = 0; k < j; k++) { + max = Math.max(max, game[i][j] - game[r][j] - game[i][k] + game[r][k]); + } + } + } + } + System.out.println(max); + } +} \ No newline at end of file diff --git "a/BOJ/5001-10000\353\262\210/YJ_8979.java" "b/BOJ/5001-10000\353\262\210/YJ_8979.java" new file mode 100644 index 00000000..e46d0aa1 --- /dev/null +++ "b/BOJ/5001-10000\353\262\210/YJ_8979.java" @@ -0,0 +1,75 @@ +import java.io.*; +import java.util.*; + +public class YJ_8979 { + static class Nation implements Comparable { + int name; + int gold; + int silver; + int bronze; + + public Nation(int name, int gold, int silver, int bronze) { + this.name = name; + this.gold = gold; + this.silver = silver; + this.bronze = bronze; + } + + @Override + public int compareTo(Nation o) { + if(this.gold == o.gold){ + if(this.silver == o.silver){ + return o.bronze - this.bronze; + } + return o.silver - this.silver; + } + return o.gold - this.gold; + } + } + + static PriorityQueue pq = new PriorityQueue<>(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + for(int i=0; i{ + int x; + int y; + int number; + int direction; + + Chess (int x, int y, int number, int direction){ + this.x = x; + this.y = y; + this.number = number; + this.direction = direction; + } + + @Override + public int compareTo(Chess c){ + return this.number - c.number; + } + } + + static final int NUM = 4; + static final Chess EMPTY = new Chess(0,0,0,0); + static Chess[][] game = new Chess[NUM][NUM]; + static PriorityQueue pq = new PriorityQueue<>(); + static int score = 0; + static Chess tagger; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + //초기값 세팅 + for(int i=0; i deque = new ArrayDeque<>(); + Chess maxThief = EMPTY; + + boolean[][] visited = new boolean[NUM][NUM]; + deque.offer(tagger); + visited[tagger.x][tagger.y] = true; + + while(!deque.isEmpty()){ + Chess tagger = deque.poll(); + for (int i=0; i<8; i++){ + int tempX = tagger.x + nx[i]; + int tempY = tagger.y + ny[i]; + //술래말은 도둑말이 없는 곳으로는 이동할 수 없습니다 + if(stop(tempX,tempY) || visited[tagger.x][tagger.y] || game[tempX][tempY].number == 0){ + continue; + } + + visited[tagger.x][tagger.y] = true; + Chess thief = game[tempX][tempY]; + deque.offer(thief); + if(thief.number > maxThief.number){ + maxThief = thief; + } + } + } + + if(maxThief.number != 0){ + game[tagger.x][tagger.y] = EMPTY; //기존에 술래가 있던 위치 빈공간으로 만들기 + //술래 위치 이동 + score += maxThief.number; + tagger = game[maxThief.x][maxThief.y]; + game[maxThief.x][maxThief.y] = null; + return true; + } + return false; //도둑말을 잡지 못했다면 게임 종료 + } + + + private static boolean stop(int x, int y){ + return x < 0 || x >= NUM || y < 0 || y >= NUM; + } +} diff --git a/Programmers/Level2/YJ_250135.java b/Programmers/Level2/YJ_250135.java new file mode 100644 index 00000000..81522281 --- /dev/null +++ b/Programmers/Level2/YJ_250135.java @@ -0,0 +1,29 @@ +public class YJ_250135 { + public int solution(int h1, int m1, int s1, int h2, int m2, int s2) { + int answer = getAlarms(h2,m2,s2)-getAlarms(h1,m1,s1); + return s1==0 && m1==0? answer+1 : answer; + } + + int getAlarms(int h, int m, int s){ + int alarms = 0; + + int mCount = h * (60-1) + m; //1시간에 59번(60분 제외) + 1분당 1번 + int hCount = h * 60 + m; + if(h>=12) { + hCount--; //24시인 경우 -1 + } + + + //초침과 분침이 겹칠 경우 + if(s*6 >= m*6 + s*0.1){ // 초침의 각도 = s * 360/60 , 분침의 각도 = m * 360/60 + s * 360/(60*60) + mCount++; + } + //초침과 시침이 겹칠 경우 + if(30*(h%12) + 0.5*m + s * ((double) 1 / 120) <= s*6){ // 시침의 각도 = (h%12) * 360/12 + m * 360/(12*60) + s * 360 / (12*60*60) + hCount++; + } + + alarms = mCount + hCount; + return h>=12? alarms-1 : alarms; + } +} diff --git "a/SQL/13\354\243\274\354\260\250/YJ_Students and Examinations.sql" "b/SQL/13\354\243\274\354\260\250/YJ_Students and Examinations.sql" new file mode 100644 index 00000000..1447c038 --- /dev/null +++ "b/SQL/13\354\243\274\354\260\250/YJ_Students and Examinations.sql" @@ -0,0 +1,8 @@ +SELECT + s.student_id, s.student_name, su.subject_name, COUNT(e.subject_name) attended_exams +FROM Students s +CROSS JOIN Subjects su +LEFT JOIN Examinations e +ON s.student_id = e.student_id AND su.subject_name = e.subject_name +GROUP BY s.student_id, s.student_name, su.subject_name +ORDER BY s.student_id, su.subject_name \ No newline at end of file diff --git "a/SQL/13\354\243\274\354\260\250/YJ_\353\214\200\354\227\254 \355\232\237\354\210\230\352\260\200 \353\247\216\354\235\200 \354\236\220\353\217\231\354\260\250\353\223\244\354\235\230 \354\233\224\353\263\204 \353\214\200\354\227\254 \355\232\237\354\210\230 \352\265\254\355\225\230\352\270\260.sql" "b/SQL/13\354\243\274\354\260\250/YJ_\353\214\200\354\227\254 \355\232\237\354\210\230\352\260\200 \353\247\216\354\235\200 \354\236\220\353\217\231\354\260\250\353\223\244\354\235\230 \354\233\224\353\263\204 \353\214\200\354\227\254 \355\232\237\354\210\230 \352\265\254\355\225\230\352\270\260.sql" new file mode 100644 index 00000000..7b2d0dce --- /dev/null +++ "b/SQL/13\354\243\274\354\260\250/YJ_\353\214\200\354\227\254 \355\232\237\354\210\230\352\260\200 \353\247\216\354\235\200 \354\236\220\353\217\231\354\260\250\353\223\244\354\235\230 \354\233\224\353\263\204 \353\214\200\354\227\254 \355\232\237\354\210\230 \352\265\254\355\225\230\352\270\260.sql" @@ -0,0 +1,17 @@ +-- 2022년 8월부터 2022년 10월까지 총 대여 횟수가 5회 이상인 자동차들에 대해서 +-- 해당 기간 동안의 월별 자동차 ID 별 총 대여 횟수(컬럼명: RECORDS) +-- 월을 기준으로 오름차순 정렬, 월이 같다면 자동차 ID를 기준으로 내림차순 정렬 +WITH CAR_COUNT AS( + SELECT CAR_ID + FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY + WHERE DATE_FORMAT(START_DATE,'%Y-%m') BETWEEN '2022-08' AND '2022-10' + GROUP BY CAR_ID + HAVING COUNT(CAR_ID) >= 5 +) +SELECT + MONTH(START_DATE) MONTH, CAR_ID, COUNT(CAR_ID) RECORDS +FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY +WHERE CAR_ID IN (SELECT * FROM CAR_COUNT) + AND DATE_FORMAT(START_DATE,'%Y-%m') BETWEEN '2022-08' AND '2022-10' +GROUP BY MONTH(START_DATE), CAR_ID +ORDER BY MONTH(START_DATE), CAR_ID DESC \ No newline at end of file