-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from nahokyun/main
나호균 / 10월 1주차 / 목
- Loading branch information
Showing
6 changed files
with
423 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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<right) { | ||
mid=(left+right)>>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; | ||
} | ||
|
||
} |
This file contains 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,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<Pair> 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;i<m;i++){ | ||
st=new StringTokenizer(br.readLine()); | ||
|
||
int first=Integer.parseInt(st.nextToken()); | ||
int second=Integer.parseInt(st.nextToken()); | ||
|
||
nodes[first].next=new Node(nodes[first].next,second); | ||
nodes[second].next=new Node(nodes[second].next,first); | ||
} | ||
|
||
Collections.sort(breakPoint); | ||
|
||
for(Pair cur:breakPoint){ | ||
find(cur.num); | ||
} | ||
|
||
StringBuilder sb=new StringBuilder(); | ||
for(int i=1;i<=n;i++){ | ||
sb.append(dp[i]).append('\n'); | ||
} | ||
System.out.println(sb); | ||
|
||
} | ||
private static void find(int cur){ | ||
int max=0; | ||
for(Node next=nodes[cur].next;next!=null;next=next.next){ | ||
if(dp[next.num]>max){ | ||
max=dp[next.num]; | ||
} | ||
} | ||
|
||
dp[cur]=max+1; | ||
|
||
} | ||
|
||
static class Pair implements Comparable<Pair>{ | ||
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; | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
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<curLength) { | ||
dp[i][j]=dp[i-1][j]; | ||
continue; | ||
} | ||
for (int count = 0; count <= pipes[i].quantity; count++) { | ||
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; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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,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); | ||
|
||
} | ||
} |
This file contains 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,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<Integer>[] 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]); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.