From 80cc8ac0c5d2f1abd396b3bbab927021d0801ccc Mon Sep 17 00:00:00 2001 From: Na hokyun <100259486+nahokyun@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:25:10 +0900 Subject: [PATCH] =?UTF-8?q?=EB=82=98=ED=98=B8=EA=B7=A0=20/=2010=EC=9B=94?= =?UTF-8?q?=201=EC=A3=BC=EC=B0=A8=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Nahokyun/boj/boj1300.java | 51 ++++++++++++++++++ Nahokyun/boj/boj14699.java | 98 ++++++++++++++++++++++++++++++++++ Nahokyun/boj/boj15817.java | 68 ++++++++++++++++++++++++ Nahokyun/boj/boj17404.java | 44 ++++++++++++++++ Nahokyun/boj/boj18427.java | 57 ++++++++++++++++++++ Nahokyun/boj/boj2660.java | 105 +++++++++++++++++++++++++++++++++++++ 6 files changed, 423 insertions(+) create mode 100644 Nahokyun/boj/boj1300.java create mode 100644 Nahokyun/boj/boj14699.java create mode 100644 Nahokyun/boj/boj15817.java create mode 100644 Nahokyun/boj/boj17404.java create mode 100644 Nahokyun/boj/boj18427.java create mode 100644 Nahokyun/boj/boj2660.java diff --git a/Nahokyun/boj/boj1300.java b/Nahokyun/boj/boj1300.java new file mode 100644 index 00000000..a35a9516 --- /dev/null +++ b/Nahokyun/boj/boj1300.java @@ -0,0 +1,51 @@ +package boj; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class boj1300 { + + private static long n; + private static long k; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + + n = Integer.parseInt(br.readLine()); + k = Integer.parseInt(br.readLine()); + + + long left=0; + long right=n*n; + long mid=0; + + while(left+1>1; + + if(check(mid)) { + left=mid; + }else { + right=mid; + } + } + System.out.println(right); + + } + + private static boolean check(long mid) { + long count=0; + + for(long i=1;i<=n;i++) { + count+=mid/i>=n?n:mid/i; + + if(count>=k) {//수가 많으면 false 리턴 =>수를 줄여야함 + return false; + } + } + + + return count>=k?false:true; + } + +} diff --git a/Nahokyun/boj/boj14699.java b/Nahokyun/boj/boj14699.java new file mode 100644 index 00000000..f6f3be32 --- /dev/null +++ b/Nahokyun/boj/boj14699.java @@ -0,0 +1,98 @@ +package boj; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + +public class boj14699 { + + private static Node[] nodes; + private 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()); + + int n=Integer.parseInt(st.nextToken()); + int m=Integer.parseInt(st.nextToken()); + + st=new StringTokenizer(br.readLine()); + + ArrayList breakPoint=new ArrayList<>(); + dp = new int[n+1]; + + for(int i=1;i<=n;i++){ + breakPoint.add(new Pair(Integer.parseInt(st.nextToken()),i)); + } + + nodes = new Node[n+1]; + for(int i=1;i<=n;i++){ + nodes[i]=new Node(null,i); + } + + + for(int i=0;imax){ + max=dp[next.num]; + } + } + + dp[cur]=max+1; + + } + + static class Pair implements Comparable{ + int height; + int num; + + public Pair(int height, int num) { + this.height = height; + this.num = num; + } + + @Override + public int compareTo(Pair o) { + return o.height-this.height; + } + } + + + static class Node{ + Node next; + int num; + + public Node(Node next, int num) { + this.next = next; + this.num = num; + } + } +} diff --git a/Nahokyun/boj/boj15817.java b/Nahokyun/boj/boj15817.java new file mode 100644 index 00000000..40e13602 --- /dev/null +++ b/Nahokyun/boj/boj15817.java @@ -0,0 +1,68 @@ +package boj; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class boj15817 { + + 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 x = Integer.parseInt(st.nextToken()); + + Pipe[] pipes = new Pipe[n+1]; + int[][] dp = new int[n+1][x + 1]; + + for (int i = 1; i <= n; i++) { + st = new StringTokenizer(br.readLine()); + int l = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + pipes[i] = new Pipe(l, c); + + } + // 입력 종료 + + + dp[0][0]=1; + for (int i = 1; i <= n; i++) { + int curLength=pipes[i].length; + for (int j = 0; j <= x; j++) { + if(j==0) { + dp[i][j]=1; + continue; + } + if(j= count * curLength) { + dp[i][j]+=dp[i-1][j-curLength*count]; + } + } + } + } + + + + System.out.println(dp[n][x]); + } + + static class Pipe { + int length; + int quantity; + + public Pipe(int length, int quantity) { + super(); + this.length = length; + this.quantity = quantity; + } + + } + +} diff --git a/Nahokyun/boj/boj17404.java b/Nahokyun/boj/boj17404.java new file mode 100644 index 00000000..5a2b9140 --- /dev/null +++ b/Nahokyun/boj/boj17404.java @@ -0,0 +1,44 @@ +package boj; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class boj17404 { + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + + int[][] colors = new int[n][3]; + int[][] dp = new int[n][3]; + for (int i = 0; i < n; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + colors[i][j] = Integer.parseInt(st.nextToken()); + } + } + //입력 종료 + + + int result=10000000; + for(int c=0;c<3;c++) { + for(int i=0;i<3;i++){ + dp[0][i]=i==c?colors[0][i]:10000; + } + + for (int i = 1; i < n; i++) { + dp[i][0] = (Math.min(dp[i - 1][1], dp[i - 1][2])) + colors[i][0]; + dp[i][1] = (Math.min(dp[i - 1][0], dp[i - 1][2])) + colors[i][1]; + dp[i][2] = (Math.min(dp[i - 1][0], dp[i - 1][1])) + colors[i][2]; + } + + for(int i = 0 ; i < 3; i++) + if(i != c) + result = Math.min(result, dp[n-1][i]); + } + System.out.println(result); + + } +} diff --git a/Nahokyun/boj/boj18427.java b/Nahokyun/boj/boj18427.java new file mode 100644 index 00000000..c0557416 --- /dev/null +++ b/Nahokyun/boj/boj18427.java @@ -0,0 +1,57 @@ +package boj; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class boj18427 { + + 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 m = Integer.parseInt(st.nextToken()); + int h = Integer.parseInt(st.nextToken()); + + int[][] dp = new int[n + 1][h + 1]; + ArrayList[] al=new ArrayList[n+1]; + + + for (int i = 1; i <= n; i++) { + al[i]=new ArrayList<>(); + st=new StringTokenizer(br.readLine()); + while(st.hasMoreTokens()) { + al[i].add(Integer.parseInt(st.nextToken())); + } + + + al[i].add(0); + } + // 입력 종료 + dp[0][0] = 1; + + for (int i = 1; i <= n; i++) { + dp[i][0]=1; + for (int k = 1; k <= h; k++) { + int tmp = 0; + for (int j = 0; j < al[i].size(); j++) { + int cur = al[i].get(j); + + if(cur<=k){ + tmp+=dp[i-1][k-cur]%10007; + } + + } + dp[i][k] = tmp%10007; + } + } + + System.out.println(dp[n][h]); + + } + +} diff --git a/Nahokyun/boj/boj2660.java b/Nahokyun/boj/boj2660.java new file mode 100644 index 00000000..cfcd48c8 --- /dev/null +++ b/Nahokyun/boj/boj2660.java @@ -0,0 +1,105 @@ +package boj; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + +public class boj2660 { + + private static Node[] relation; + private static int n; + + public static void main(String[] args) throws NumberFormatException, IOException { + // TODO Auto-generated method stub + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + n = Integer.parseInt(br.readLine()); + relation = new Node[n + 1]; + + for (int i = 1; i <= n; i++) { + relation[i] = new Node(null, i); + } + + while (true) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int first = Integer.parseInt(st.nextToken()); + int second = Integer.parseInt(st.nextToken()); + + if (first == -1 && second == -1) { + break; + } + + relation[first].next = new Node(relation[first].next, second); + relation[second].next = new Node(relation[second].next, first); + } + // 입력 종료 + + int[] score = new int[n + 1]; + for (int i = 1; i <= n; i++) { + score[i] = bfs(i); + } + + ArrayList al = new ArrayList<>(); + int min = n+2; + for (int i = 1; i <= n; i++) { + if (score[i] < min) { + al.clear(); + al.add(i); + min = score[i]; + } else if (score[i] == min) { + al.add(i); + } + } + + Collections.sort(al); + StringBuilder sb = new StringBuilder(); + sb.append(min-1).append(" ").append(al.size()).append("\n"); + for (int i : al) { + sb.append(i).append(" "); + } + + System.out.println(sb.toString()); + } + + private static int bfs(int i) { + ArrayDeque q = new ArrayDeque<>(); + q.add(i); + boolean[] visited = new boolean[n + 1]; + visited[i] = true; + int depth = 0; + while (!q.isEmpty()) { + ArrayDeque tmp = new ArrayDeque<>(); + + while (!q.isEmpty()) { + int cur = q.poll(); + + for (Node next = relation[cur].next; next != null; next = next.next) { + if (!visited[next.num]) { + tmp.add(next.num); + visited[next.num] = true; + } + } + + } + depth++; + q = tmp; + } + + return depth; + } + + static class Node { + Node next; + int num; + + public Node(Node next, int num) { + super(); + this.next = next; + this.num = num; + } + } +}