diff --git "a/BOJ/1000-5000353円262円210円/SB_1256.java" "b/BOJ/1000-5000353円262円210円/SB_1256.java" new file mode 100644 index 00000000..b2f8e535 --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/SB_1256.java" @@ -0,0 +1,68 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class SB_1256 { + static int N, M, K; + static long[][] dp; + 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()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + dp = new long[N+1][M+1]; + + // dp배열 만들기 + dp[0][0] = 1; // 아무것도 못만드는 경우 1개 + for (int i = 1; i <= N; i++) { // a만으로 이루어진 경우 + dp[i][0] = 1; + } + for (int j = 1; j <= M; j++) { // z만으로 이루어진 경우 + dp[0][j] = 1; + } + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= M; j++) { + dp[i][j] = Math.min(dp[i - 1][j] + dp[i][j - 1], K); // a를 앞에 추가해서 만들기 + z를 앞에 추가해서 만들기 + } + } + + // K가 범위 벗어나면 -1 + if (dp[N][M] < K) { + System.out.println(-1); + return; + } + + // 사전순으로 문자열 만들기 + while (N> 0 && M> 0) { + long tmp = dp[N - 1][M]; // a로 시작하는 문자열의 개수 + if (K <= tmp) { // K가 tmp(a로 시작하는 범위의 개수)에 속할경우 + N -= 1; // 현재 tmp에서 N=-1해서 다음 경우 살피기 (현재 자리값 고정, 다음 자리 확인) + sb.append('a'); // a로 시작하기에 a붙이기 + } else { // K가 tmp보다 클 경우 z를 시작으로하는 범위에서 살피기 + M -= 1; // M=-1해서 다음 경우 살피기 + K -= tmp; // K에서 제외된 tmp값 빼주기 + sb.append('z'); // z로 시작하기에 z붙이기 + } + } + + // 남은 문자 처리 + while (N> 0) { + sb.append('a'); + N--; + } + + while (M> 0) { + sb.append('z'); + M--; + } + + System.out.println(sb); + + } +} diff --git "a/BOJ/1000-5000353円262円210円/SB_1405.java" "b/BOJ/1000-5000353円262円210円/SB_1405.java" new file mode 100644 index 00000000..5b815e35 --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/SB_1405.java" @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class SB_1405 { + static int N; + static int[] dx = {0, 0, 1, -1}; // 동, 서, 남, 북 + static int[] dy = {1, -1, 0, 0}; + static double[] prob = new double[4]; + static boolean[][] visited = new boolean[30][30]; + static double ans = 0; + + private static void dfs(int x, int y, int depth, double total) { + if (depth==N) { + ans += total; + return; + } + + for (int i = 0; i < 4; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + if (!visited[nx][ny]){ // 방문하지 않은 곳이라면 + visited[nx][ny] = true; + dfs(nx, ny, depth+1, total*prob[i]); + visited[nx][ny] = false; + } + } + } + + 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()); + for (int i = 0; i < 4; i++) { + prob[i] = Integer.parseInt(st.nextToken())*0.01; // 확률로 표현 + } + + visited[15][15] = true; + dfs(15, 15, 0, 1); + System.out.println(ans); + } +} diff --git "a/BOJ/1000-5000353円262円210円/SB_1938.java" "b/BOJ/1000-5000353円262円210円/SB_1938.java" new file mode 100644 index 00000000..48c6988e --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/SB_1938.java" @@ -0,0 +1,140 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class SB_1938 { + static int N; + static int[][] board; + static int[][][] visited; + static Node target; + static int[] dx = {-1, 1, 0, 0, 0}; + static int[] dy = {0, 0, -1, 1, 0}; + + private static int bfs(Node start) { + Queue que = new ArrayDeque(); + que.offer(start); + visited[start.x][start.y][start.ty] = 0; + + while (!que.isEmpty()) { + Node cur = que.poll(); + if (cur.x==target.x && cur.y== target.y && cur.ty== target.ty) return visited[cur.x][cur.y][cur.ty]; + + for (int i = 0; i < 5; i++) { + int nx = cur.x + dx[i]; + int ny = cur.y + dy[i]; + if (!isValid(nx, ny) || board[nx][ny]==1) continue; // 중심좌표가 범위 벗어나면 패쓰 + + if (i==4) { // 회전할때 경우 + int nt = cur.ty ^ 1; + if(canTurn(nx, ny, nt) && visited[nx][ny][nt]==-1) { + que.offer(new Node(nx, ny, nt)); + visited[nx][ny][nt] = visited[cur.x][cur.y][cur.ty] + 1; + } + continue; + } + + // 상하좌우로 움직인 nx,ny 값에 대해 가로,세로일때 각 양날개가 가능한지 체크 + if (cur.ty == 0 && canWingRow(nx, ny) && visited[nx][ny][cur.ty]==-1) { + que.offer(new Node(nx, ny, cur.ty)); + visited[nx][ny][cur.ty] = visited[cur.x][cur.y][cur.ty] + 1; + } else if (cur.ty == 1 && canWingCol(nx, ny) && visited[nx][ny][cur.ty]==-1) { + que.offer(new Node(nx, ny, cur.ty)); + visited[nx][ny][cur.ty] = visited[cur.x][cur.y][cur.ty] + 1; + } + } + } + return 0; + } + + private static boolean canWingRow(int r, int c) { // 가로일때 날개 유효한지 + return isValid(r, c-1) && isValid(r, c+1) && board[r][c - 1] == 0 && board[r][c + 1] == 0; + } + + private static boolean canWingCol(int r, int c) { // 세로일때 날개 유효한지 + return isValid(r-1, c) && isValid(r+1, c) && board[r-1][c] == 0 && board[r+1][c] == 0; + } + + private static boolean canTurn(int r, int c, int t) { + for (int i = r - 1; i <= r + 1; i++) { + for (int j = c - 1; j <= c + 1; j++) { + if (!isValid(i, j) || board[i][j]==1) return false; + } + } + return true; + } + + private static boolean isValid(int x, int y) { // 좌표 유효성 검사 + return 0<=x && x b = new ArrayList(); + List e = new ArrayList(); + for (int i=0; i { + if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]); + return Integer.compare(o1[1], o2[1]); + }); + + Collections.sort(e, (o1, o2) -> { + if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]); + return Integer.compare(o1[1], o2[1]); + }); + + // 처음 중심 좌표 및 형태 + int tb = (b.get(0)[0] == b.get(1)[0]) ? 0 : 1; // 가로(0), 세로(1) + int te = (e.get(0)[0] == e.get(1)[0]) ? 0 : 1; + Node start = new Node(b.get(1)[0], b.get(1)[1], tb); // 중간값이 중심값 + target = new Node(e.get(1)[0], e.get(1)[1], te); + + System.out.println(bfs(start)); + } + + static class Node{ + int x, y, ty; + + public Node(int x, int y, int ty) { + this.x = x; + this.y = y; + this.ty = ty; + } + + @Override + public String toString() { + return "Node{" + + "x=" + x + + ", y=" + y + + ", ty=" + ty + + '}'; + } + } + +} diff --git "a/BOJ/10001-15000353円262円210円/SB_13334.java" "b/BOJ/10001-15000353円262円210円/SB_13334.java" new file mode 100644 index 00000000..c89bb183 --- /dev/null +++ "b/BOJ/10001-15000353円262円210円/SB_13334.java" @@ -0,0 +1,52 @@ +package PriorityQueue; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class SB_13334 { + static int N, d; + static PriorityQueue pq = new PriorityQueue(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + N = Integer.parseInt(br.readLine()); + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int s = Integer.parseInt(st.nextToken()); + int e = Integer.parseInt(st.nextToken()); + pq.offer(new Node(Math.min(s, e), Math.max(s, e))); // 집과 사무실 중 작은게 시작, 큰게 끝 + } + d = Integer.parseInt(br.readLine()); + + PriorityQueue pre = new PriorityQueue(); // 이전 사람들의 정보를 저장하는 우선순위 큐 + int mx = 0; + while (!pq.isEmpty()) { + Node cur = pq.poll(); + int start = cur.e - d; // 철로의 시작 지점 + pre.offer(cur.s); // 현재 노드의 시작지점을 pre큐에 넣어주기 + while (!pre.isEmpty() && pre.peek() < start) { // 이전 사람들이 현재 철로에 속하지 못하면 빼주기 + pre.poll(); + } + mx = Math.max(mx, pre.size()); + } + + System.out.println(mx); + } + + static class Node implements Comparable{ + int s, e; + + public Node(int s, int e) { + this.s = s; + this.e = e; + } + @Override + public int compareTo(Node o) { + if (this.e-o.e!=0) return this.e - o.e; + return this.s-o.s; + } + } +} diff --git "a/SQL/19354円243円274円354円260円250円/SB_Immediate Food Delivery II.sql" "b/SQL/19354円243円274円354円260円250円/SB_Immediate Food Delivery II.sql" new file mode 100644 index 00000000..6b0a5fcb --- /dev/null +++ "b/SQL/19354円243円274円354円260円250円/SB_Immediate Food Delivery II.sql" @@ -0,0 +1,7 @@ +SELECT ROUND(AVG(order_date = customer_pref_delivery_date)*100,2) as immediate_percentage +FROM Delivery +WHERE (customer_id, order_date) in ( + SELECT customer_id, min(order_date) + FROM Delivery + GROUP BY customer_id +) \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /