๐Ÿฏ ์•Œ๊ณ ๋ฆฌ์ฆ˜/BOJ

๋ฐฑ์ค€ 1์ฃผ์ฐจ(1)

๊ณ„๋ž€์†Œ๋…„ 2025. 1. 5. 23:24

๋งค์ผ ์ตœ์†Œ ํ•œ ๋ฌธ์ œ์”ฉ ํ’€๊ณ , ์ƒ๊ฐ๊ณผ์ • ์ •๋ฆฌ

 

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])