๋งค์ผ ์ต์ ํ ๋ฌธ์ ์ฉ ํ๊ณ , ์๊ฐ๊ณผ์ ์ ๋ฆฌ
1์ผ์ฐจ(1/6)
https://www.acmicpc.net/problem/2839
5,3์ ๋ฐฐ์๊ด๊ณ๊ฐ ์๋๊ธฐ์, ๋จ์ํ ๊ตฌํ๋ ์ซ์๋ฅผ 5๋ก ๋๋ ๋๋จธ์ง์ ๋ํ ๋ฌด๊ฒ๋ฅผ 3์ผ๋ก ๋๋๋ ๋ฐฉ์์ผ๋ก ํ๋ฉด ์๋๋ค.
์ ๊ทผ ๋ฐฉ๋ฒ
1. 5kg ๋ด์ง๋ฅผ ์ต๋ํ ๋ง์ด ์ฌ์ฉํ๋ ๊ฒ์ด ์ ๋ฆฌํ๋ค.
N์์ 5kg ๋ด์ง ๊ฐฏ์๋ฅผ ์ค์ฌ๊ฐ๋ฉฐ ๋๋จธ์ง๊ฐ 3kg๋ก ๋๋ ์ง๋์ง ํ์ธ
N์์ 3์ ๋บ ์ซ์๊ฐ 5๋ก ๋๋ ์ง๋์ง๋ฅผ ๋ด์ผํจ. ex) 18 -> 15: 5๋ก ๋๋ ์ง
์ด๋ N์์๋ 3์ ๋นผ๊ณ , answer๋ 1์ ๋ํ๋ฉด๋๋ค.
2. N์ 3,5๋ก ์ ํํ ๋ชป ๋๋๋ฉด ๋ชป ๊ตฌํ๋ ๊ฒ -> -1
def solution(n):
answer=0
while n>=0: #n=7 -> 3,3,1
if n%5==0:
answer+=n//5
return answer
else:
n-=3
answer+=1
return -1
n=int(input()) #18 -> 5 5 5 3
print(solution(n))
https://www.acmicpc.net/problem/11931
๋ ๋น ๋ฅธ ๋ฐฉ๋ฒ์ด ์๊ธด ํ๊ฒ ์ง๋ง, ๋ฌธ์ ํธ๋๋ฐ ์ง์ฅ์ ์๋ค.
์ถ๊ฐ๋ก ๊ธฐ๋ณธ input ์ฌ์ฉ์ ์๊ฐ ์ด๊ณผ ๋ฐ์
import sys
input = sys.stdin.readline
n = int(input())
li = []
for _ in range(n):
answer = int(input())
li.append(answer)
li.sort(reverse=True)
for i in li:
print(i)
2์ผ์ฐจ(1/7)
https://www.acmicpc.net/problem/1764
๋น๊ต์ด๊ธฐ์ ํด์๋ฅผ ๋ ์ฌ๋ ธ๋ค.
a ๋์ ๋๋ฆฌ๋ฅผ ๋ง๋ค๊ณ ๊ธฐ์กดํค ์ ๋ฌด๋ก ํ์ ์ ํจ, b๊ฐ ์ด๋ฅผ ๋๋ฉฐ ํด๋น ๊ฐ์ด a ๋์ ๋๋ฆฌ์ ์์ผ๋ฉด ํ์๊ฐ 2๊ฐ ๋ ๊ฒ
๋์ ๋๋ฆฌ ๋๋ฉด์ ํ์ 2์ธ ๋ฌธ์์ด ์ฐพ๊ณ , ์ด ํ์์ ๊ฐ ๋จ์ด ๋ฆฌ์คํธ์์ print ํ๋ ๊ฒ์๋ ์ฌ๋ ธ๋ค.
์ค๋ณต๋ ๋จ์ด๋ ๊ฐ ๋์ ๋๋ฆฌ์ ๋์ค์ง ์๊ธฐ์, ์ถ๊ฐ ๊ณ ๋ ค ์ฌํญ์ ์๋ค๊ณ ํ๋จํ์๋ค.
a,b=map(int,input().split())
a_dic={}
b_dic={}
for _ in range(a):
a_input=input()
if a_input not in a_dic:
a_dic[a_input]=1
else:
a_dic[a_input]+=1
for _ in range(b):
b_input=input()
if b_input not in a_dic:
a_dic[b_input]=1
else:
a_dic[b_input]+=1
ans=0
ans_li=[]
for k,v in a_dic.items():
if v==2:
ans+=1
ans_li.append(k)
print(ans)
ans_li.sort()
for i in ans_li:
print(i)
3์ผ์ฐจ(1/8)
https://www.acmicpc.net/problem/10867
n=int(input())
arr=list(map(int,input().split()))
set_arr=set(arr)
set_arr.sort()
sorted_set_arr=sorted(set_arr)
for i in sorted_set_arr:
print(i,end=' ')
https://www.acmicpc.net/problem/17219
n,m = map(int,input().split())
dic={}
for _ in range(n):
k,v = input().split()
dic[k] =v
for _ in range(m):
ans = input()
if ans in dic:
print(dic[ans])
https://www.acmicpc.net/problem/8958
n = int(input())
ans=0
for _ in range(n):
ans=0
judgment=0
arr=input()
for string in arr:
if string=='O':
judgment+=1
ans+=judgment
else:
judgment=0
print(ans)
https://www.acmicpc.net/problem/2789
words= input()
w=''
for word in words:
if word not in 'CAMBRIDGE':
w+=word
print(w)
https://www.acmicpc.net/problem/14582
2๊ฐ์ง ํฌ์ธํธ
- ์ด์ ๋ง์ ๋ฐ๋ก ๊ตฌ๋ถํด์ผํ๋ค.
- ๋ง์ง๋ง 9ํ๋ง์ ์ญ์ ํจํ ๊ฒฝ์ฐ๋ฅผ ๋๋ฝํด์๋ ์๋๋ค.
one = list(map(int,input().split()))
two = list(map(int,input().split()))
ans=0
one_buf=0
two_buf=0
win = False #์ด๊ธด์ ์ด ์๋์ง
for i in range(len(one)):
one_buf+=one[i]
if one_buf > two_buf:
win = True
if win and one_buf < two_buf:
ans += 1
break
two_buf+=two[i]
if win and one_buf < two_buf:
ans+=1
if ans!=0:
print('Yes')
else:
print('No')
https://www.acmicpc.net/problem/7510
2๊ฐ์ง ํฌ์ธํธ
- ์ค๊ฐ์ ๊ฐํ ํ์
- ์ซ์๊ฐ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฅ๋๋ค๋ ๋ณด์ฅ ์์
n=int(input())
for i in range(n):
arr = list(map(int, input().split()))
arr.sort()
print(f'Scenario #{i+1}:')
if arr[0]*arr[0] + arr[1]*arr[1] == arr[2]*arr[2]:
print('yes')
else:
print('no')
if i != n-1:
print()
https://www.acmicpc.net/problem/1302
๋๋ฐ๋ก ๋ณด๊ณ , ๊ฑฐ๊พธ๋ก ๋ด๋ ๋์ ๋๋ฆฌ
๊ฐฏ์๋ฅผ ๋ด๋ฆผ์ฐจ์, ๊ฐฏ์ ๊ฐ์ผ๋ฉด ๋จ์ด๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํ์ฌ ๊ฐ์ฅ ์์ ์ฑ ์ด ๋ฒ ์คํธ์ ๋ฌ
n=int(input())
dic={}
for _ in range(n):
book = input()
if book in dic:
dic[book]+=1
else:
dic[book]=1
sorted_books = sorted(dic.items(), key=lambda x: (-x[1], x[0]))
print(sorted_books[0][0])
'๐ฏ์๊ณ ๋ฆฌ์ฆ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 2์ฃผ์ฐจ (0) | 2025.01.12 |
---|---|
๋ฐฑ์ค 1์ฃผ์ฐจ(2) (0) | 2025.01.08 |
DP (0) | 2024.06.27 |
[๋ฐฑ์ค/Python] 10844:์ฌ์ด ๊ณ๋จ ์ (0) | 2024.06.27 |
[๋ฐฑ์ค/Python] 11726:2รn ํ์ผ๋ง (0) | 2024.06.27 |