๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”‘ ์•Œ๊ณ ๋ฆฌ์ฆ˜

[์ด์ฝ”๋‹ค] ๊ทธ๋ฆฌ๋‹ค & ๊ตฌํ˜„ ์‹ค์ „๋ฌธ์ œ

by Tamii 2021. 7. 23.
๋ฐ˜์‘ํ˜•

์‹œ๊ฐ„์ œํ•œ1 ์ดˆ ๋ฐ์ดํ„ฐ :100๋งŒ๊ฐœ => O ( n log n)

p.96 ์ˆซ์ž์นด๋“œ๊ฒŒ์ž„

 

๋‚ดํ’€์ด

ํ’€์ด์‹œ๊ฐ„ ์‹œ๊ฐ„๋ณต์žก๋„
20m O(N log N)
def solution ():
    n,m = map(int,input().split())

    for i in range(n):
        matrix.append(min(list(map(int, input().split()))))
    print(max(matrix))
    result= 0



solution()

 

๋ฐฐ์šด์ 

๋‹ต์˜ ํ›„๋ณด๋“ค์„ ๋ฐฐ์—ด์— ๋„ฃ์ง€ ๋ง๊ณ  ๊ทธ๋ƒฅ ๋‘๊ฐ€์ง€ ๊ฐ’์„ ๋ฐ”๋กœ max๋กœ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹๋‹ค

result = 0

for i in arr:
	result = max(i,result)

 

p.100 ์ˆซ์ž์นด๋“œ

ํ’€์ด์‹œ๊ฐ„ ์‹œ๊ฐ„๋ณต์žก๋„
20m O(N log N)

๋‚ด ์ฝ”๋“œ

def solution():
    n,k = map(int,input().split())
    cnt=0
    while n!=1:
        if n%k ==0:
            n = n/k
            cnt+=1
        else:
            n-=1
            cnt+=1
    print(cnt)
solution()

๋ฐฐ์šด์ 

์˜ˆ์™ธ์— ๋Œ€ํ•œ ์ƒ๊ฐ์„ ํ•ญ์ƒ ํ•ด์•ผํ•œ๋‹ค.

 

๊ตฌํ˜„ - p.110 ์ƒํ•˜์ขŒ์šฐ

ํ’€์ด์‹œ๊ฐ„ ์‹œ๊ฐ„๋ณต์žก๋„
12m O(N^2)

๋‚ด ํ’€์ด

def solution ():
    n = int(input())
    go = input().split()
    loc = [1,1]

    for i in go:
        if i == 'R':
            if loc[1]+1<=n:
                loc[1]+=1
        elif i == 'L':
            if loc[1]-1>1:
                loc[1]-=1
        elif i == 'U':
            if loc[0]-1>1:
                loc[0]-=1
        else:
            if loc[0]+1<n:
                loc[0]+=1
    print(" ".join(map(str,loc)))

        
solution()

๋ฐฐ์šด์ 

 

์ž…๋ ฅ์‹œ ์ˆซ์ž๋กœ ๋ณ€๊ฒฝํ•  ๊ฒŒ ์•„๋‹ˆ๋ฉด map์„ ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค

 

 

 

๋ฐฐ์šด์  ๋ชจ์Œ 

๋ฌธ์ž์—ด์ด ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง€๊ณ  ๊ทธ ์ˆœ์„œ๋ฅผ ์ด์šฉํ•ด์•ผ ํ•  ๋•Œ 

ord๋ฅผ ์ด์šฉํ•˜๊ณ  ์ฒซ๋ฒˆ์งธ ๊ฐ’์„ ๋นผ๋ฒ„๋ฆฌ๋ฉด  ์ˆœ์„œ๊ฐ€ ๋‚˜์˜จ๋‹ค 

input = 'b'
step = ['a','b','c']

ord(input)- ord(step[0]) // 1 ์ธ๋ฑ์Šค๊ฐ€ ๋‚˜์˜ด

 

๊ตฌํ˜„ - p.118 ๊ฒŒ์ž„ ๊ฐœ๋ฐœ

ํ’€์ด์‹œ๊ฐ„ ์‹œ๊ฐ„๋ณต์žก๋„
2h O(N^3)?
def solution():
    n,m = map(int,input().split())
    x,y,v = map(int,input().split())
    #์ง€๋‚˜์˜จ ๊ธฐ๋ก
    d = [[0]*m for _ in range(n)]
    direction = [[-1,0],[0,1],[1,0],[0,-1]]

    d[x][y]=1
    arr=[]
    #์ง€๋„๋ฐฐ์—ด๋ฐ›๊ธฐ
    for i in range(n):
        temp = list(map(int,input().split()))
        arr.append(temp)
    cnt=0
    ans=1
    #์™ผ์ชฝ์œผ๋กœ ๋„๋Š” ๋™์ž‘
    def turnLeft(v):
        v-=1
        if v == -1:
            v =3
        return v
    
    while True:
        v=turnLeft(v)
        addX,addY = direction[v]
        newX,newY = x+addX, y+addY

        if arr[newX][newY] ==0 and d[newX][newY]==0:
            d[newX][newY]=1
            x,y = newX,newY
            cnt=0
            ans+=1
            continue
        else:
            cnt+=1
        if cnt==4:
            backX,backY =direction[v]
            newX,newY = x-backX, y-backY 
            if arr[newX][newY] == 0:
                x,y = newX,newY
            else:
                break
            cnt=0
    print(ans)


solution()

๋ณต์žกํ•œ ๋ฌธ์ œ๋ผ ์˜ค๋ž˜ ๊ฑธ๋ ธ๋‹ค. 

์ฐจ๋ถ„ํžˆ ์ƒ๊ฐํ•˜๋ฉด ํ’€ ์ˆ˜์žˆ๋Š” ๋ฌธ์ œ์˜€์ง€๋งŒ ์ง‘์ค‘์„ ํ•˜์ง€ ๋ชปํ•ด์„œ ์˜ค๋ž˜๊ฑธ๋ ธ๋‹ค.

๋ฐฐ์—ด ์ดˆ๊ธฐํ™” ํ•˜๋Š”๋ฒ•๊ณผ , ์œ„์น˜๋ฅผ ์›€์ง์ด๋Š” ๊ฒƒ์€ d๋กœ ์ผ€์ด์Šค๋ฅผ ์ •ํ•ด์•ผ ํ•จ์„ ๊นจ๋‹ฌ์•˜๋‹ค.

 

์ง€๋‚œ๋ฐ ๋‹ค์‹œ ์ง€๋‚˜๊ธฐ ๊ธˆ์ง€ = ๋˜‘๊ฐ™์€ ๋ฐฐ์—ด ๋งŒ๋“ค์–ด์„œ ํ”์  ํ‘œ์‹œ

์œ„์น˜ ๊ฐ’ ์›€์ง์ธ๋Š ๊ฒƒ = dx,dy ,direction ๋“ฑ์„ ๋งŒ๋“ค์–ด์„œ case๋ณ„๋กœ ์ƒ๊ฐํ•ด๋‚ด๊ธฐ

๋Œ“๊ธ€