Skip to content

Kcm sds3 #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 cmkim/BaekJoon/백준_1039.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@

from _collections import deque
from itertools import combinations
import sys, copy


def bfs():
c = set()
answer = 0
qlen = len(q)
while qlen:
x = q.popleft()
l = list(str(x))
for i, j in d:
s = copy.deepcopy(l)
temp_i, temp_j = s[i], s[j]
s[i], s[j] = temp_j, temp_i
if s[0] == '0':
continue
nx = int(''.join(s))
if nx not in c:
answer = max(answer, nx)
c.add(nx)
q.append(nx)
qlen -= 1
return answer


n, k = map(int, input().split())
item = [i for i in range(len(str(n)))]
d = list(combinations(item, 2))
#print(d)
q = deque()
q.append(n)

ans = 0
while k:
ans = bfs()
k -= 1
if not ans:
print(-1)
else:
print(ans)

71 changes: 40 additions & 31 deletions cmkim/BaekJoon/백준_1062.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
def main():
n = int(input())
k = int(input())
result = 0
if k < 5:
return result
ord_cc = list(map(int, input().split())) # 후보 추천 순서

frame = []
score = []

for i in range(k):
if ord_cc[i] in frame:
for j in range(len(frame)):
if ord_cc[i] == frame[j]:
score[j] += 1
else:
if len(frame) >= n:
for j in range(n):
if score[j] == min(score):
del frame[j]
del score[j]
break
frame.append(ord_cc[i])
score.append(1)
# print(score)
# print(frame)
frame.sort()
print(' '.join(map(str, frame)))

main()

from itertools import combinations
from string import ascii_lowercase

antatica = ['a', 'c', 'i', 'n', 't']

def brute_force(alpha, cnt):
if cnt == k:
temp = 0
for i in range(n):
flag = 0
for j in range(len(check[i])):
if not alphabet[]

n, k = map(int, input().split())
if k < 5:
print(0)
return

arr = [list(map(str, input())) for _ in range(n)]
alphabet = [False] * 26
for i in range(5):
alphabet[ord(antatica[i]) - ord('a')] = True
print(alphabet)
#teach = list(combinations(list(ascii_lowercase), k - 5))
word = []
for i in range(n):
word.append(arr[i][4:-4])

for i in range(n):
check = []

for j in range(len(word[i])):
if word[i][j] not in antatica:
check.append(word[i][j])
check = set(check)

brute_force(0, 0)
#for i in range(len(check)):


24 changes: 24 additions & 0 deletions cmkim/BaekJoon/백준_1072.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def main():

x, y = map(int, input().split())

z = int(y * 100 / x)

if z >= 99:
print(-1)
return 0

answer = 1000000000
start, end = 1, 1000000000
while start <= end:
mid = (start + end) // 2
nextz = int((y + mid) * 100 / (x + mid))
if z < nextz:
if mid < answer:
answer = mid
end = mid - 1
else:
start = mid + 1

print(answer)
main()
11 changes: 11 additions & 0 deletions cmkim/BaekJoon/백준_1202.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
n, k = map(int, input().split())
jewel = [[0, 0] for _ in range(n)]
bag = [0 for _ in range(k)]
for i in range(n):
jewel[i] = list(map(int, input().split()))

for i in range(k):
bag[i] = int(input())

print(jewel)
print(bag)
2 changes: 2 additions & 0 deletions cmkim/BaekJoon/백준_14476.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
n = int(input())
arr = list(map(int, input().split()))
40 changes: 40 additions & 0 deletions cmkim/BaekJoon/백준_15663.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from itertools import permutations

n, m = map(int, input().split())
n_list = list(map(int, input().split()))
n_list = sorted(n_list)

output = []
for numbers in list(permutations(n_list, m)):
output.append(numbers)
output = sorted(list(set(output)))

for numbers in output:
for num in numbers:
print(num, end=' ')
print('\n')
# def recur(k):
# if k == m:
# for i in range(k):
# print(answer[i], end=' ')
# print('')
# return
# prev = 0
# for i in range(n):
# if used[i]: continue
# if k > 0 and answer[k - 1] > arr[i]: continue
#
# if prev != arr[i]:
# used[i] = True
# answer[k] = arr[i]
# prev = arr[i]
# recur(k + 1)
# used[i] = False
#
#
# n, m = map(int, input().split())
# used = [False for _ in range(8)]
# arr = list(map(int, input().split()))
# answer = [-1 for _ in range(m)]
# arr.sort()
# recur(0)
41 changes: 41 additions & 0 deletions cmkim/BaekJoon/백준_15686.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from itertools import combinations
n, m = map(int, input().split())

arr = []
chicken = []
home = []

for i in range(n):
temp = list(map(int, input().split()))
for j in range(n):
if temp[j] == 1:
home.append((i, j))
elif temp[j] == 2:
chicken.append((i, j))

m_chicken = list(combinations(chicken, m))

def get_sum(candidate):
result = 0
for hx, hy in home:
temp = 1e9
for cx, cy in candidate:
temp = min(temp, abs(hx - cx) + abs(hy - cy))
result += temp
return result

result = 1e9
for i in m_chicken:
result = min(result, get_sum(i))


print(result)

'''
5 3
0 0 1 0 0
0 0 2 0 1
0 1 2 0 0
0 0 1 0 0
0 0 0 0 2
'''
32 changes: 32 additions & 0 deletions cmkim/BaekJoon/백준_1713.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def main():
n = int(input())
k = int(input())
result = 0
if k < 5:
return result
ord_cc = list(map(int, input().split())) # 후보 추천 순서

frame = []
score = []

for i in range(k):
if ord_cc[i] in frame:
for j in range(len(frame)):
if ord_cc[i] == frame[j]:
score[j] += 1
else:
if len(frame) >= n:
for j in range(n):
if score[j] == min(score):
del frame[j]
del score[j]
break
frame.append(ord_cc[i])
score.append(1)
# print(score)
# print(frame)
frame.sort()
print(' '.join(map(str, frame)))

main()

13 changes: 13 additions & 0 deletions cmkim/BaekJoon/백준_1735.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def gcd(a, b):
if b == 0: return a
else: return gcd(b, a % b)

a, b = map(int, input().split())
c, d = map(int, input().split())

p = a * d + b * c
q = b * d

g = gcd(p, q)

print(p//g, q//g)
34 changes: 34 additions & 0 deletions cmkim/BaekJoon/백준_1759.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
vowels = ['a', 'e', 'i', 'o', 'u']

l, c = map(int, input().split())
arr = list(map(str, input().split()))
arr.sort()
answer = [''] * l


def recur(a, b):
if a == l:
if check():
print("".join(answer))

return

for i in range(b, c):
answer[a] = arr[i]
recur(a + 1, i + 1)


def check():
m_count, j_count = 0, 0 # 모음, 자음 카운트
for i in range(l):
if answer[i] in vowels: # 모음이라면
m_count += 1
else:
j_count += 1
if m_count >= 1 and j_count >= 2:
return True
else:
return False


recur(0, 0)
16 changes: 16 additions & 0 deletions cmkim/BaekJoon/백준_1922.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import heapq

n = int(input())
m = int(input())
arr = [list(map(int, input().split())) for _ in range(m)]
# com = [[] for _ in range(n+1)]
# for _ in range(m):
# s, e, c = map(int, input().split())
# com[s].append([e, c])
# com[e].append([s, c])

#com.sort(key=lambda x: x[2])
#com = sorted(com, key=lambda k: k[2])
#arr = sorted(arr, key=lambda k: k[2])
arr.sort(key=lambda x: x[2])
print(arr)
31 changes: 31 additions & 0 deletions cmkim/BaekJoon/백준_2003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
n, m = map(int, input().split())

arr = list(map(int, input().split()))

answer = 0

#완전 탐색 pypy3로만 통과
# for start in range(0, len(arr)):
# sum = 0
# for end in range(start, len(arr)):
# sum += arr[end]
# if sum == m:
# answer += 1
# break
# elif sum > m:
# break

#투포인터 방식으로는 어떻게 풀까? 고민하기
sum = 0
start = 0
for end in range(len(arr)):
sum += arr[end]
while sum > m:
sum -= arr[start]
start += 1
if sum == m:
answer += 1



print(answer)
20 changes: 20 additions & 0 deletions cmkim/BaekJoon/백준_2748.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
n = int(input())

dp = [[0] for _ in range(n+1)]

dp[0], dp[1] = 0, 1


if n > 1:
for i in range(2, n+1):
dp[i] = dp[i-1] + dp[i-2]

# 이건 왜 안될까?
# dp[1], dp[2] = 1, 1
#
#
# if n>2:
# for i in range(3, n+1):
# dp[i] = dp[i-1] + dp[i-2]

print(dp[n])
Loading