Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions 01월/4주차/[BOJ] 배/Mun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.io.*;
import java.util.*;

public class Mun {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> crane = new ArrayList<>();
ArrayList<Integer> box = new ArrayList<>();

int N = Integer.parseInt(br.readLine());
String[] c_input = br.readLine().split(" ");
for(String c : c_input) {
crane.add(Integer.parseInt(c));
}
int M = Integer.parseInt(br.readLine());
String[] b_input = br.readLine().split(" ");
for(String b : b_input) {
box.add(Integer.parseInt(b));
}

Collections.sort(crane, Collections.reverseOrder());
Collections.sort(box, Collections.reverseOrder());

if(crane.get(0) < box.get(0)) {
System.out.print(-1);
return;
}
int time = 0;
while(box.size() > 0) {
time++;
for(int cSize : crane) {
for(int i=0;i<box.size();i++) {
if(cSize >= box.get(i)) {
box.remove(i);
break;
}
}
}
}
System.out.print(time);
}
}
46 changes: 46 additions & 0 deletions 01월/4주차/[BOJ] 음하철도 구구팔/Mun.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해결하기 어려운 문제였던거같은데 덕분에 풀이법 배워갑니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io.*;
public class Mun {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] station = br.readLine().split(" ");
int xs = Integer.parseInt(station[0]);
int ys = Integer.parseInt(station[1]);
String[] train = br.readLine().split(" ");
int xe = Integer.parseInt(train[0]);
int ye = Integer.parseInt(train[1]);
int dx = Integer.parseInt(train[2]);
int dy = Integer.parseInt(train[3]);
int gcd = getGcd(dx, dy);
dx /= gcd;
dy /= gcd;
double distance = getDis(xs, xe, ys, ye);
int x = 0;
int y = 0;
while(true) {
xe += dx;
ye += dy;
double dis = getDis(xs, xe, ys, ye);
if(distance > dis) {
distance = dis;
} else {
x = xe - dx;
y = ye - dy;
break;
}
}
System.out.print(x + " " + y);
}

private static double getDis(int x1, int x2, int y1, int y2) {
return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
}

public static int getGcd(int a, int b) {
if(b == 0) {
return a;
}
return getGcd(b, a % b);

}

}
37 changes: 37 additions & 0 deletions 01월/4주차/[BOJ] 좋은 구간/Mun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.io.*;
import java.util.*;

public class Mun {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int L = Integer.parseInt(br.readLine());
int[] S = Arrays.stream(br.readLine().split(" "))
.mapToInt(Integer::parseInt)
.sorted()
.toArray();
int n = Integer.parseInt(br.readLine());
int min = 0;
int max = S[L-1];
for(int i=0;i<L;i++) {
if(S[i] >= n) {
max = S[i];
if(i > 0) {
min = S[i-1];
}
break;
}
}
if(min == n || max == n) {
System.out.print(0);
return;
}
int count = 0;
for(int i=min+1;i<=n;i++) {
for(int j=n;j<max;j++) {
count++;
}
}
count--;
System.out.print(count);
}
}
39 changes: 39 additions & 0 deletions 01월/4주차/[PRGRMS] 택배 배달과 수거하기/Mun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Mun {

public long solution(int cap, int n, int[] deliveries, int[] pickups) {
long answer = 0;
int start = getStart(deliveries, pickups, n);
while(start >= 0) {
answer+=((start+1)*2);
start = Math.max(go(start, cap, deliveries), go(start, cap, pickups));
}
return answer;
}

private int go(int start, int cap, int[] arr) {
for(int i=start;i>=0;i--) {
if(arr[i] == 0) {
continue;
}
int a = arr[i];
if(a <= cap) {
arr[i] = 0;
cap -= a;
continue;
}
arr[i]-=cap;
return i;
}
return -1;
}

private int getStart(int[] a1, int[] a2, int n) {
for(int i=n-1;i>=0;i--) {
if(a1[i] > 0 || a2[i] > 0) {
return i;
}
}
return -1;
}

Comment on lines +30 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시작 구간을 처음부터 정해놓고 시작해서 확실히 불필요한 부분은 연산이 안들어가니까 좋은거같아요!!

}