7์ผ์ฐจ(1/13)
https://www.acmicpc.net/problem/1181
๋๋ค๋ฅผ ์ธ ์ ์๋๋
lists = []
n = int(input())
for _ in range(n):
lists.append(input().strip())
set_lists = set(lists)
# ๊ธธ์ด ์ฐ์ -> ์ฌ์ ์
sorted_lists = sorted(set_lists, key=lambda x: (len(x), x))
for word in sorted_lists:
print(word)
https://www.acmicpc.net/problem/10825
์ด๋, ๋๋ค์์ -๋ฅผ ๋ถ์ฌ์ ๋ด๋ฆผ์ฐจ์์ ํํํ๋๋ฐ,
๋๋ค์ ๊ธฐ๋ณธ ์ ๋ ฌ์ ์ค๋ฆ์ฐจ์์ด๋ค. ๋ด๋ฆผ์ฐจ์์ ์ํด์ -๋ฅผ ๋ถ์ด๊ฑฐ๋, ๋งค๊ฐ๋ณ์๋ก reverse=True๋ฅผ ์จ์ผํ๋๋ฐ
- ๋ฅผ ๋ถ์ผ๋๋, ํด๋น ์ธ์๊ฐ ์ซ์ํ ๋ฐ์ดํฐ์ฌ์ผ ํ๋ค. ์ด๋ฅผ ์ํด ๋ณํ์ ํ๊ณ ์ ๋ ฌํด์ผํ๋ค.
n=int(input())
lists=[]
for _ in range(n):
name,korean,english,math=input().split()
lists.append([name,int(korean),int(english),int(math)])
sorted_lists = sorted(lists, key=lambda x:(-x[1],x[2],-x[3],x[0]))
for nm in sorted_lists:
print(nm[0])
๋ง์ฝ ์ฌ๋ฌ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ ๋, ๋ฌธ์์ด์ธ๋ฐ ๋ด๋ฆผ์ฐจ์์ ์ํ๋ค๋ฉด, ์ฌ๋ผ์ด์ฑ์ ํ์ฉํ๋ค.
x[0][::-1]
https://www.acmicpc.net/problem/2729
t = int(input())
for _ in range(t):
a, b = input().split()
print(bin(int(a, 2) + int(b, 2))[2:])
8์ผ์ฐจ(1/14)
https://www.acmicpc.net/problem/5533
n = int(input())
arr = []
score = [0] * n
for _ in range(n):
arr.append(list(map(int, input().split())))
for i in range(3):
dic = {}
for j in range(n):
if arr[j][i] in dic:
dic[arr[j][i]] += 1
else:
dic[arr[j][i]] = 1
for j in range(n):
if dic[arr[j][i]] == 1:
score[j] += arr[j][i]
for s in score:
print(s)
https://www.acmicpc.net/problem/7696
def find(n): #25 -> 27
num=[0]*10002
cur_num = 1 # ํ์ฌ ํ์ ์ค์ธ ์ซ์
cnt = 0 # ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์ซ์์ ๊ฐ์
while True:
str_cur_num = str(cur_num)
if len(str_cur_num) == len(set(str_cur_num)):
cnt += 1
num[cnt] = cur_num
if cnt == n:
print(num)
return cur_num
cur_num+=1
#14๋ฒ์งธ ์ 13
#13๋ฒ์งธ ์ 14
while True:
num = int(input())
if num==0:
break
print(find(num))
์๋ ์ด๊ฑฐ -> ์๊ฐ์ด๊ณผ
def find(limit):
non_repeating_numbers = []
cur_num = 1
# ์ค๋ณต ์ฒดํฌ๋ฅผ ์ํ ๋ฐฐ์ด (0~9๊น์ง ๊ฐ ์ซ์๊ฐ ๋์จ ์ ์ด ์๋์ง ์ฒดํฌ)
while len(non_repeating_numbers) < limit:
check = [False] * 10 # ๊ฐ ์๋ฆฌ์์ ์ซ์๊ฐ ๋์จ ์ ์ด ์๋์ง ์ฒดํฌ
num = cur_num
is_duplicate = False
# ๊ฐ ์๋ฆฟ์ ํ์ธ
while num > 0:
digit = num % 10
if check[digit]: # ์ด๋ฏธ ๋์จ ์ซ์๋ผ๋ฉด ์ค๋ณต
is_duplicate = True
break
check[digit] = True
num //= 10
# ์ค๋ณต๋์ง ์๋ ์๋ฉด ๋ฆฌ์คํธ์ ์ถ๊ฐ
if not is_duplicate:
non_repeating_numbers.append(cur_num)
cur_num += 1
return non_repeating_numbers
max_limit = 1000000
non_repeating_numbers = find(max_limit)
while True:
num = int(input())
if num == 0:
break
print(non_repeating_numbers[num - 1])
9์ผ์ฐจ(1/15)
https://www.acmicpc.net/problem/1932
์ ํ์ ์ธ DP๋ฌธ์
๋๋ ์๋์์ ์ฌ๋ผ์ค๋๊ฑธ ์ข์ํด์, ์ด๊ฑธ๋ก ํ์๋ค. ์ด๋, range๋ฒ์๋ฅผ ์ ๊ณ ๋ คํด์ผํ๋ค.
n=int(input())
arr=[[0]*n for i in range(n)]
dp=[[0]*n for i in range(n)]
for i in range(n):
lists=list(map(int,input().split()))
for j in range(len(lists)):
arr[i][j]=lists[j]
for i in range(n):
dp[-1][i]=arr[-1][i]
for i in range(n-2,-1,-1):
for j in range(i+1):
dp[i][j] = arr[i][j] + max(dp[i+1][j],dp[i+1][j+1])
print(dp[0][0])
10์ผ์ฐจ(1/16)
https://www.acmicpc.net/problem/1966
from collections import deque
n=int(input())
for _ in range(n):
cnt,order = map(int,input().split()) #order๋ง ์ง์ค order๋ฒ์งธ ์ซ์ ์ฐพ๊ธฐ
arr= deque(map(int,input().split()))
find = arr[order]
order_pop=0
while arr:
max_num = max(arr)
cur = arr.popleft()
if cur != max_num:
arr.append(cur)
else:
order_pop+=1
if find not in arr:
print(order_pop)
break
์ด๋ ๊ฒ ๋๋ฉด, ์ค์๋๊ฐ ๊ฐ์ ๋ถ๋ถ์ ์ฒ๋ฆฌ ๋ชปํ๋ค. -> ์ด ํ์์, ์ธ๋ฑ์ค๋ง ํจ๊ป ์ฒ๋ฆฌํ๋ ๋ฐฉ์ ์๊ฐ
from collections import deque
n = int(input())
for _ in range(n):
cnt, order = map(int, input().split()) #order๋ง ์ง์ค order๋ฒ์งธ ์ซ์ ์ฐพ๊ธฐ
arr = deque((priority, idx) for idx, priority in enumerate(map(int, input().split())))
order_pop = 0
while arr:
max_priority = max(arr, key=lambda x: x[0])[0]
cur_priority, cur_idx = arr.popleft()
if cur_priority == max_priority:
order_pop += 1
if cur_idx == order:
print(order_pop)
break
else:
arr.append((cur_priority, cur_idx))
11์ผ์ฐจ(1/17)
https://www.acmicpc.net/problem/14888
n=int(input())
num_list = list(map(int, input().split()))
add,minus,multiple,divide=map(int,input().split())
op_dic = {'+': add, '-': minus, '*': multiple, '/': divide}
arr=[]
for op,cnt in op_dic.items():
for _ in range(cnt):
arr.append(op)
from itertools import permutations
operation = set(permutations(arr,n-1))
max_result = -float('inf')
min_result = float('inf')
for op_seq in operation:
result = num_list[0]
for i in range(1, n):
if op_seq[i - 1] == '+':
result += num_list[i]
elif op_seq[i - 1] == '-':
result -= num_list[i]
elif op_seq[i - 1] == '*':
result *= num_list[i]
elif op_seq[i - 1] == '/':
if result < 0:
result = -(-result // num_list[i])
else:
result //= num_list[i]
max_result = max(max_result, result)
min_result = min(min_result, result)
print(max_result)
print(min_result)
12์ผ์ฐจ(1/18)
https://www.acmicpc.net/problem/17609
์ฒ์ ์ฝ๋
def is_palindrome(words):
length = len(words)
palindrome_cnt = 0
for i in range(length // 2):
if words[i] != words[length - (i + 1)]:
palindrome_cnt += 1
if palindrome_cnt == 0:
return 0
for i in range(length):
temp = words[:i] + words[i + 1:]
palindrome_cnt = 0
for j in range(len(temp) // 2):
if temp[j] != temp[len(temp) - (j + 1)]:
palindrome_cnt += 1
if palindrome_cnt == 0:
return 1
return 2
t= int(input())
for _ in range(t):
words= input()
print(is_palindrome(words))
์๊ฐ์ด๊ณผ
์ฌ๋ผ์ด์ฑ์์ ์๊ฐ๋ณต์ก๋๊ฐ O(n)๋งํผ ์ถ๊ฐ๋ก ๋ค์ด ์ต์ข ์ ์ผ๋ก O(n^2)๊ฐ ๋๋ค.
ํฌ์ธํฐ๋ฅผ ์ฌ์ฉํ์ฌ ํด๊ฒฐํ์
def is_palindrome(words):
def is_valid_palindrome(s, left, right):
while left < right:
if s[left] != s[right]:
return False
left += 1
right -= 1
return True
length = len(words)
left, right = 0, length - 1
while left < right:
if words[left] != words[right]:
if is_valid_palindrome(words, left + 1, right) or is_valid_palindrome(words, left, right - 1):
return 1
return 2
left += 1
right -= 1
return 0
t= int(input())
for _ in range(t):
words= input()
print(is_palindrome(words))
https://www.acmicpc.net/problem/15666
def generate_sequence(arr, sequence, m, start):
if len(sequence) == m:
print(" ".join(map(str, sequence)))
return
for i in range(start, len(arr)):
generate_sequence(arr, sequence + [arr[i]], m, i)
n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(set(arr))
generate_sequence(arr, [], m, 0)
'๐ฏ์๊ณ ๋ฆฌ์ฆ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 1์ฃผ์ฐจ(2) (0) | 2025.01.08 |
---|---|
๋ฐฑ์ค 1์ฃผ์ฐจ(1) (0) | 2025.01.05 |
DP (0) | 2024.06.27 |
[๋ฐฑ์ค/Python] 10844:์ฌ์ด ๊ณ๋จ ์ (0) | 2024.06.27 |
[๋ฐฑ์ค/Python] 11726:2รn ํ์ผ๋ง (0) | 2024.06.27 |