Skip to content
Open
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
71 changes: 71 additions & 0 deletions 김동하/2학기/[Baekjoon-10159] 저울.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import java.io.*;
import java.util.*;

public class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static StringBuilder sb = new StringBuilder();

public static int n,m;

public static List<Integer>[] arr;
public static List<Integer>[] rev;

public static void init() throws IOException {
n = Integer.parseInt(br.readLine());
m = Integer.parseInt(br.readLine());

arr = new ArrayList[n + 1];
rev = new ArrayList[n + 1];

for (int i = 1; i <= n; i++) {
arr[i] = new ArrayList<>();
rev[i] = new ArrayList<>();
}
for(int i = 0; i < m; i++) {
int a,b;
StringTokenizer st = new StringTokenizer(br.readLine());
a = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());
arr[a].add(b);
rev[b].add(a);
}
}

public static int bfs(int x, List<Integer>[] list){
Queue<Integer> q = new ArrayDeque<>();
q.add(x);
boolean[] visited = new boolean[n + 1];
visited[x] = true;
int cnt = 0;
while(!q.isEmpty()){
int cur = q.poll();
visited[cur] = true;
for(int next : list[cur]) {
if(!visited[next]){
q.add(next);
visited[next] = true;
cnt++;
}
}
}
return cnt;
}

public static void solution() throws IOException {
init();
for(int i = 1; i <= n; i++){
sb.append(n - 1 - bfs(i,arr) - bfs(i, rev)).append("\n");
}

}

public static void main(String[] args)throws IOException {
solution();

bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
}
71 changes: 71 additions & 0 deletions 김동하/2학기/[Baekjoon-1561] 놀이 공원.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import java.io.*;
import java.util.*;

public class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static StringBuilder sb = new StringBuilder();

public static int n,m;
public static int[] arr;


public static void init() throws IOException {
StringTokenizer stk = new StringTokenizer(br.readLine());
n = Integer.parseInt(stk.nextToken());
m = Integer.parseInt(stk.nextToken());
arr = new int[m + 1];
stk = new StringTokenizer(br.readLine());
for (int i = 1; i <= m; i++) {
arr[i] = Integer.parseInt(stk.nextToken());
}
}

public static long binarySearch() {
long st = 0;
long ed = 60000000000L;
while (st <= ed) {
long mid = (st + ed) / 2;
long sum = m;
for(int i = 1; i <= m; i++) {
sum += mid / arr[i];
}
if(sum < n) {
st = mid + 1;
}
else {
ed = mid - 1;
}
}
return st;
}

public static void solution() throws IOException {
init();
if(n <= m) sb.append(n).append("\n");
else {
long time = binarySearch();
long sum = m;
for(int i = 1; i <= m; i++) {
sum += (time - 1) / arr[i];
}

for(int i = 1; i <= m; i++) {
if(time % arr[i] == 0) sum++;
if(sum == n) {
sb.append(i).append("\n");
return;
}
}
}
}

public static void main(String[] args)throws IOException {
solution();

bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
}
49 changes: 49 additions & 0 deletions 김동하/2학기/[Baekjoon-17390] 이건꼭풀어야해.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.io.*;
import java.util.*;

public class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static StringBuilder sb = new StringBuilder();

public static int n,q;
public static int[] arr;
public static int[] sum;

public static void init() throws IOException {
StringTokenizer stk = new StringTokenizer(br.readLine());
n = Integer.parseInt(stk.nextToken());
q = Integer.parseInt(stk.nextToken());
arr = new int[n];
sum = new int[n];
stk = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++){
arr[i] = Integer.parseInt(stk.nextToken());
}
Arrays.sort(arr);
sum[0] = arr[0];
for(int i = 1; i < n; i++){
sum[i] = sum[i-1] + arr[i];
}
for(int i = 0; i < q; i++) {
int a,b;
stk = new StringTokenizer(br.readLine());
a = Integer.parseInt(stk.nextToken()) - 1;
b = Integer.parseInt(stk.nextToken()) - 1;
sb.append(sum[b] - sum[a] + arr[a]).append('\n');
}
}

public static void solution() throws IOException {
init();
}

public static void main(String[] args)throws IOException {
solution();

bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
}
65 changes: 65 additions & 0 deletions 김동하/2학기/[Baekjoon-9935] 문자열 폭발.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static StringBuilder sb = new StringBuilder();

public static String str;
public static String word;

public static List<Character> stack = new ArrayList<>();


public static void init() throws IOException {
str = br.readLine();
word = br.readLine();
}

public static void solution() throws IOException {
init();
int len = str.length();
char ed = word.charAt(word.length() - 1);
for (int i = 0; i < len; i++) {
stack.add(str.charAt(i));
if (str.charAt(i) == ed) {
boolean flag = true;
int idx = word.length() - 1;
if(stack.size() < word.length()) continue;
for(int j = stack.size() - 1; j >= stack.size() - word.length(); j--) {
if(stack.get(j) != word.charAt(idx)) {
flag = false;
break;
}
idx--;
}
if(flag) {
int x = stack.size() - 1;
for(int j = x; j >= x - word.length() + 1; j--) {
stack.remove(j);
}
}
}
}
if(stack.isEmpty()) {
sb.append("FRULA");
return;
}
for(int i = 0; i < stack.size(); i++) {
sb.append(stack.get(i));
}
}

public static void main(String[] args)throws IOException {
solution();

bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
}