Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Feb 4, 2021
1 parent c3ca68c commit 2256202
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 16 deletions.
22 changes: 22 additions & 0 deletions argorithm/number_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
input = sys.stdin.readline

N = int(input())
N_arr = sorted(list(map(int, input().split())))
M = int(input())
M_arr = list(map(int, input().split()))

for marr in M_arr:
answer = 0
start = 0
end = len(N_arr) - 1
while start <= end:
mid = (start + end) // 2
if N_arr[mid] > marr:
end = mid-1
elif N_arr[mid] < marr:
start = mid+1
else:
answer = 1
break
print(answer, end=' ')
20 changes: 20 additions & 0 deletions argorithm/selfish_panda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys
input = sys.stdin.readline

n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
temp = 0


def dfs(a, t, i, j):
visited[i][j] = True
a[i][j]
pass


while True:
visited = [[False] * n for _ in range(n)]
for i_i, i in enumerate(arr):
for i_j, j in enumerate(arr):
if not visited[i_i][i_j] and arr[i_i][i_j] > temp:
dfs(arr, temp, i_i, i_j)
15 changes: 15 additions & 0 deletions argorithm/two_liquid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
input = sys.stdin.readline

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

min = sys.maxsize
answer = 0
for a in arr:
for b in arr:
if a+b < min:
min = abs(a+b)
answer = a, b
for i in sorted(answer):
print(i, end=' ')
24 changes: 24 additions & 0 deletions argorithm/two_liquid_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
input = sys.stdin.readline

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

start = 0
end = len(arr)-1

min = sys.maxsize
while start < end:
calc = arr[start] + arr[end]
if abs(calc) < min:
min = abs(calc)
answer = arr[start], arr[end]
if calc == 0:
break
if calc < 0:
start += 1
else:
end -= 1

for i in sorted(answer):
print(i, end=' ')
31 changes: 15 additions & 16 deletions argorithm/word_math.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import sys
from itertools import permutations
input = sys.stdin.readline

N = int(input())
words = [list(input().rstrip()) for _ in range(N)]
all_words_duplicate = set(sum(words, []))
num = [i for i in range(10)]

# # 순열
# perm = set(permutations(num, len(all_words_duplicate)))
word_dict = {}

for p in set(permutations(num, len(all_words_duplicate))):
# print(list(zip(all_words_duplicate, p)))
# print(p)
for key, value in list(zip(all_words_duplicate, p)):
print(key, value)
for word in words:
pass
# 숫자 이어 붙힘
for word in words:
k = len(word)-1
for w in word:
if w in word_dict:
word_dict[w] += 10 ** k
else:
word_dict[w] = 10 ** k
k -= 1

# 계산해

# 최댓값
sorted_word = sorted(word_dict.values(), reverse=True)
answer, num = 0, 9
for sw in sorted_word:
answer += sw * num
num -= 1
print(answer)

0 comments on commit 2256202

Please sign in to comment.