Skip to content

Instantly share code, notes, and snippets.

View qkreltms's full-sized avatar
💖
Happy coding

JungHoonPark qkreltms

💖
Happy coding
View GitHub Profile
def baekjoon11399(length, times_to_wait_in_line):
times_to_wait_in_line.sort()
cal = sum(times_to_wait_in_line)
result = cal
for i in range(length - 1, 0, -1):
cal -= times_to_wait_in_line[i]
result += cal
return result
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static int solve(int length, int[] times_to_wait_in_line) {
Arrays.sort(times_to_wait_in_line);
int cal = Arrays.stream(times_to_wait_in_line)
.reduce((a, b) -> a + b)
.getAsInt();
@qkreltms
qkreltms / baekjoon1931.java
Last active March 5, 2018 03:36
baekjoon 1931 : 회의실 배정 https://www.acmicpc.net/problem/1931
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class Meeting {
public int start;
public int end;
public Meeting(int start, int end) {
this.start = start;
# 앞, 뒤 두번 정렬 하는 이유는 [1, 1], [2, 2], [1, 2], [2, 2]같은 반례가 있음
class Meeting:
def __init__(self, begin, end):
self.begin = begin
self.end = end
def algorithm1931():
meeting_list = []
for x in range(int(input())):
@qkreltms
qkreltms / approach.txt
Last active March 8, 2018 12:25
https://www.acmicpc.net/problem/1463 : 1로 만들기 <DP, top-down, bottom-up>
문제의 조건인 n이 1이 될 수 있는, 최솟값을 구할 수 있는 방법은
1. n/3
2. n/2
3. n-1
이 있다.
n에서 n/2, n/3, n-1을 거치면 횟수가 +1
한번 거친 후 조건을 n 번을 반복하므로
1 + f(n/2) ,1 + f(n/3),1 + f(n-1)
모든 조건을 거치면서 최솟값을 구한다.
예 n = 10일 때 n-1을 9번 거쳐간 값과 8번 거쳐간 후 n/2를 한 번 거쳐간 값과 비교 후 값이 작은 것을 사용한다.(이 경우 서로 같으므로 후자 값을 사용하지 않음)
@qkreltms
qkreltms / DP_fibonacci.py
Last active March 8, 2018 12:29
피보나치 DP
def fibo_bottom_up(n):
d = [0] * (n+1)
d[0] = 0
d[1] = 1
for i in range(2, n+1):
d[i] = d[i-1] + d[i-2]
return d[n]
def fibo(n):
@qkreltms
qkreltms / kakao_1_2.py
Last active March 8, 2018 12:35
카카오톡 신입 공채 1, 2번 문제 python
import re
def kakao1_2(user):
p = re.compile('[0-9]+')
p2 = re.compile(r"[A-Z]+#*\**")
f = p.findall(user)
f2 = p2.findall(user)
result = [0] * 3
for i in range(3):
@qkreltms
qkreltms / baekjoon15501.py
Last active March 9, 2018 03:55
백준 소프트콘 1회 A번 문제 https://www.acmicpc.net/problem/15501
def f(n, a, b):
d = [0] * n
dd = [0] * n
a_start_position = a.index(1)
for i in range(n):
j = a_start_position + i #
d[i] = a[j % n] - a[(j + 1) % n] # 현재 값과 다음 값의 차를 구해주는 점화식
b_start_position = b.index(1)
@qkreltms
qkreltms / kakao_1_2.java
Last active March 9, 2018 04:04
카카오톡 신입 공채 1, 2번 문제
package algorithm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author jack
문제의 조건
2 x 1(세로) 타일과
1 x 2(가로) 타일을 사용해
2 x n 타일을 채워라
1 x 2 를 사용시 1 x 2를 한 번더 사용해야하므로 2개를 1개로 취급
타일의 크기가 n 일 때 세로 타일은 n칸에서 1칸을 차지 -> n-1
n-1 1
---------