๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
๐“๐จ๐๐š๐ฒ ๐ˆ ๐‹๐ž๐š๐ซ๐ง

๐“๐จ๐๐š๐ฒ ๐ˆ ๐‹๐ž๐š๐ซ๐ง 2022.03.29.ํ™”

by DevIseo 2022. 3. 30.

Today I Learn (20220329)


์˜ค๋Š˜ ์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•๊ณผ ๊ทธ๋ฆฌ๋””, ์—๋ผํ† ์Šคํ…Œ์Šค๋„ค์˜ ์ฒด์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค.

์‚ฌ์‹ค ์ฒ˜์Œ์—๋Š” ๋‚ด๊ฐ€ ์•„๋Š” ์ˆ˜ํ•™์  ๊ฐœ๋…์ด๋ผํ•ด๋„ ๊ตฌํ˜„์„ ํ•ด๋‚ด๋Š” ๊ฒƒ์€ ๋งค์šฐ ์–ด๋ ต๊ฒŒ ๋‹ค๊ฐ€์™”๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‹œ์ž‘ํ•œ ์ง€ ๊ฑฐ์˜ ํ•œ๋‹ฌ์ด ๋˜์–ด๊ฐ€๋Š”๋ฐ, ์•„์ง ์ˆ˜ํ•™-->์ฝ”๋“œ๋กœ ๊ตฌํ˜„ ์ด ๋ถ€๋ถ„์ด ๋ถ€์กฑํ•˜๋‹ค๊ณ  ๋Š๊ปด์ง„๋‹ค. ์•ž์œผ๋กœ ๋” ๋งŽ์€ ์—ฐ์Šต์ด ํ•„์š”ํ•œ๊ฑฐ ๊ฐ™๋‹ค. ํ•˜์ง€๋งŒ ์ˆ˜ํ•™์—์„œ ๋ฐฐ์› ๋˜๊ฒƒ์„ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•ด ์‰ฝ๊ฒŒ ๊ฐ’์„ ๋‚ผ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์ด ํฅ๋ฏธ๋กญ๊ฒŒ ๋‹ค๊ฐ€์™”๋‹ค.

์˜ค๋Š˜ ๋™์ ๊ณ„ํš๋ฒ•์— ๋Œ€ํ•ด ์ผ๋ถ€ ๋ฐฐ์› ๋Š”๋ฐ, ๋งŽ์€ ์—ฐ์Šต๊ณผ ๋ณต์Šต์ด ํ•„์š”ํ•ด๋ณด์ธ๋‹ค. ์•„์ง ๊ฐœ๋…์ด ์ž˜ ์žกํžˆ์ง€ ์•Š๋Š”๋‹ค. ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ ๋งŽ์ด ์งˆ๋ฌธํ•˜๊ณ  ๋‚ด๊ฐ€ ๋ถ€์กฑํ•œ ์ ์„ ์ฑ„์›Œ๋‚˜๊ฐ€์•ผ๊ฒ ๋‹ค!



์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•


์˜๋ฏธ: ์ตœ์ดˆ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜

์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•(-ไบ’้™คๆณ•, Euclidean algorithm) ๋˜๋Š” ์œ ํด๋ฆฌ๋“œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ 2๊ฐœ์˜ ์ž์—ฐ์ˆ˜ ๋˜๋Š” ์ •์‹(ๆ•ดๅผ)์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํ•˜๋‚˜์ด๋‹ค. (์ถœ์ฒ˜:wikipedia)

<๊ตฌํ˜„>

a,b = map(int,input().split())
for i in range(min(a,b),0,-1):
    if a%i==0 and b%i==0:
        print(i)
        break
a,b = map(int,input().split())
for i in range(min(a,b),0,-1):
    if a%i==0 and b%i==0:
        print(i)
        break
a,b = map(int,input().split())

def abc(a,b):
    if b==0:
        print(a)
        return
    abc(b,(a-b)%b)

abc(a,b)
a,b = map(int,input().split())

answer = 1
while b:
    answer = a%b
    a=b
    b=answer
    
print(a)

์‘์šฉ - ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ๊ตฌํ•˜๊ธฐ


#์ˆซ์ž 2๊ฐœ ์ž…๋ ฅ๋ฐ›๊ณ  ์ž…๋ ฅ๋ฐ›์€ ๋‘ ์ˆซ์ž์˜ ์ตœ์†Œ ๊ณต๋ฐฐ์ˆ˜ ๊ตฌํ•˜๊ธฐ(least common multiple)
#lcm=gcd*(a/gcd)*(b/gcd)

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

gcd=0
def abc(a,b):
    global gcd
    if b==0:
        gcd = a
        return
    abc(b,(a-b)%b)
abc(a,b)

lcm = gcd*(a/gcd)*(b/gcd)
print(int(lcm))

์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด (์†Œ์ˆ˜ ๊ตฌํ•˜๊ธฐ)


#์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด (์†Œ์ˆ˜ ๊ตฌํ•˜๊ธฐ)
#์†Œ์ˆ˜ - 1๊ณผ ์ž๊ธฐ ์ž์‹ ๋งŒ์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋Š” ์ˆ˜
#์ž…๋ ฅ ๋ฐ›์€ ํ›„ ์ž…๋ ฅ๋ฐ›์€ ์ˆซ์ž๊ฐ€ ์†Œ์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ์ถœ๋ ฅ!
#ํžŒํŠธ 2๋ถ€ํ„ฐ ์ž๊ธฐ์ž์‹  -1 ๊นŒ์ง€ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 0์ด๋ฉด ์•ˆ๋จ

#์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์•„ ์†Œ์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•˜์‹œ์˜ค.
#๋‚ด ์ฝ”๋“œ
n = int(input())
for i in range(2,n):
    if n%i ==0:
        print('์†Œ์ˆ˜ ์•ˆ๋จ')
        break
else:
    print('์†Œ์ˆ˜ ๋จ')

#์ž…๋ ฅ 50 #์ถœ๋ ฅ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

#์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด (์†Œ์ˆ˜ ๊ตฌํ•˜๊ธฐ)
#์†Œ์ˆ˜ - 1๊ณผ ์ž๊ธฐ ์ž์‹ ๋งŒ์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋Š” ์ˆ˜

#์ž…๋ ฅ ๋ฐ›์€ ํ›„ ์ž…๋ ฅ๋ฐ›์€ ๋ฒ”์œ„๊นŒ์ง€์˜ ์†Œ์ˆ˜๋ฅผ ์ฐพ๊ธฐ
a = int(input())
answer=[]
check=[0]*(a+1) #์ง€์šธ ๊ฑฐ๋ฅผ ์ฒดํฌํ•˜๋Š” ๋ฐ•์Šค
for i in range(2,a+1): #2๋ถ€ํ„ฐ 50๊นŒ์ง€ ํ™•์ธ
    if check[i] ==0:
        answer.append(i) #์†Œ์ˆ˜๋Š” answer์— ์ €์žฅ~
		#๋‚จ์€ ์ˆ˜ ์ค‘์— ์ž‘์€ ์ˆ˜ ๋ถ€ํ„ฐ 50๊นŒ์ง€ ์ž‘์€์ˆ˜์˜ ๋ฐฐ์ˆ˜์— ํ•ด๋‹นํ•˜๋Š” index์˜ ๊ฐ’์„ 1๋กœ ์ฒดํฌ
    for j in range(i+i,a+1,i): 
        check[j]=1
print(*answer)

๊ทธ๋ฆฌ๋””(greedy)


https://www.acmicpc.net/problem/11399

#๋ณต์žก๋„ n^2
n = int(input())
people = list(map(int,input().split()))
people.sort()

total=0
for i in range(n):
    for j in range(i+1):
        total+=people[j]
print(total)
#๋ณต์žก๋„ n
a = int(input())
arr = list(map(int,input().split()))
arr.sort()
sum=0
for i in range(a):
	sum+=(arr[i]*(a-1))
print(sum)

 

 

#์˜ˆ์•ฝ์˜ ๊ฐœ์ˆ˜ ์ž…๋ ฅ๋ฐ›๊ณ , ์˜ˆ์•ฝ ์‹œ์ž‘์‹œ๊ฐ„, ๋งˆ๊ฐ์‹œ๊ฐ„ ์ž…๋ ฅ๋ฐ›์•„ ์ตœ๋Œ€ ๋ช‡๊ฐœ์˜ ์˜ˆ์•ฝ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š”์ง€

#์ž…๋ ฅ

10 #์˜ˆ์•ฝ ๊ฐœ์ˆ˜
18 21 #์˜ˆ์•ฝ ์‹œ์ž‘ ์‹œ๊ฐ„, ํŒŒํ‹ฐ ๋งˆ์น˜๋Š” ์‹œ๊ฐ„ ์ž…๋ ฅ
11 14
15 17
18 22
13 16
10 16
12 23
22 24
16 20
15 19
#1.๋๋‚˜๋Š” ์‹œ๊ฐ„ ๊ธฐ์ค€์œผ๋กœ sort
#2.๋‹ค์Œ ์‹œ์ž‘์‹œ๊ฐ„์ด ๊ทธ ์ „ ํŒŒํ‹ฐ ๋๋‚˜๋Š” ์‹œ๊ฐ„๋ณด๋‹ค๋Š” ํฌ๊ฑฐ๋‚˜ ๊ฐ™๋‹ค (๋‹ค์Œ์‹œ์ž‘ >=๊ทธ ์ „ ๋ cnt)


schedules = []
N = int(input())
for _ in range(N):
    schedules.append(list(map(int, input().split())))

schedules.sort(key=lambda x: x[1]) #ํŒŒํ‹ฐ ์ข…๋ฃŒ์‹œ๊ฐ„์„ ๊ธฐ์ค€์œผ๋กœ sortํ•˜๊ธฐ
time = 0
cnt = 0
for i in range(len(schedules)):
    if time <= schedules[i][0]: #์‹œ์ž‘ ์‹œ๊ฐ„๊ณผ ๋น„๊ต
        time = schedules[i][1] #๋ ์‹œ๊ฐ„์„ ๋Œ€์ž… ํ•ด์ฃผ๊ธฐ
        cnt += 1 #ํŒŒํ‹ฐ ์ˆ˜
print(cnt)
 
 

1931๋ฒˆ: ํšŒ์˜์‹ค ๋ฐฐ์ •

(1,4), (5,7), (8,11), (12,14) ๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

www.acmicpc.net

๋น„์Šทํ•˜์ง€๋งŒ ํ’€์ด๋ฒ•์ด ์ข€ ๋‹ฌ๋ž๋˜ ๋ฐฑ์ค€๋ฌธ์ œ... 2๋ฒˆ์ด๋‚˜ ํ‹€๋ ธ๋‹ค.

์ด ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ์—๋Š” ๋จผ์ € ์‹œ์ž‘์‹œ๊ฐ„์œผ๋กœ ์ •๋ ฌ์„ ํ•ด์ฃผ๊ณ  ๋‹ค์‹œ ์ข…๋ฃŒ์‹œ๊ฐ„์œผ๋กœ ์ •๋ ฌํ•ด์ค˜์•ผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

n = int(input())

meeting=[list(map(int,input().split())) for _ in range(n)]
meeting.sort(key=lambda x:x[0])
meeting.sort(key=lambda x:x[1])

cnt=0
time=0
for j in range(n):
    if time<=meeting[j][0]:
        time = meeting[j][1]
        cnt+=1
print(cnt)

๋Œ“๊ธ€