Skip to content

Commit

Permalink
2월 19일 알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Feb 19, 2021
1 parent 37da807 commit 365e1bb
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 10 deletions.
6 changes: 6 additions & 0 deletions argorithm/1024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys
input = sys.stdin.readline

N, L = map(int, input().split())

# 일단 포기 ^^
25 changes: 15 additions & 10 deletions argorithm/1074.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@

N, r, c = map(int, input().split())

arr = [[-1]*(2**N) for _ in range(2**N)]
print(arr)
num = 0

def z(start):
def z(x, y, z):
# 사분면 찾음
midx, midy = (2**N)//2, (2**N)//2
print(midx, midy)
# 현재 위치 이전의 사분면에 있는 갯수 다 더함
midx, midy = (2**z)//2 + x, (2**z)//2 + y

# 다시 사분면 찾음
if r < midx and c < midy:
z(midx, midy, z//2)
elif r < midx and c >= midy:
num += midx*midy
z(midx, midy, z//2)
elif r >= midx and c < midy:
num += (midx*midy) * 2
z(midx, midy, z//2)
else:
num += (midx*midy) * 3
z(midx, midy, z//2)

print(arr[r][c])
z(0, 0, N)
print(num)
26 changes: 26 additions & 0 deletions argorithm/1074_google.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
input = sys.stdin.readline

result = 0

def z(n, x, y):
global result
if x == r and y == c:
print(result)
exit(0)

if n == 1:
result += 1
return

if not (x<=r<x+n and y<=c<y+n):
result += n*n
return

z(n/2, x, y)
z(n/2, x, y+n/2)
z(n/2, x+n/2, y)
z(n/2, x+n/2, y+n/2)

n, r, c = map(int, input().split())
z(2**n, 0, 0)
33 changes: 33 additions & 0 deletions argorithm/1074_sn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys
input = sys.stdin.readline

n, r, c = map(int, input().split())

# n: 변의 길이,x: 현재 위치의 x축 값, y:현재 위치의 y축 값
result = 0
def N(n, x, y):
global result

if x==r and y==c:
print(int(result))
exit(0)

if n == 1:
result += 1
return

if not(x<=r<x+n and y<=c<y+n):
result += n*n
return

# 1사분면
N(n/2, x, y)
# 2사분면
N(n/2, x, y+n/2)
# 3사분면
N(n/2, x+n/2, y)
# 4사분면
N(n/2, x+n/2, y+n/2)

N(2**n, 0, 0)

29 changes: 29 additions & 0 deletions argorithm/1259.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
input = sys.stdin.readline

arr = []
while True:
val = input().rstrip()
if int(val) == 0:
break
arr.append(list(map(int, val)))

for a in arr:
flag = 1
if len(a)%2==0:
while a:
if a.pop() == a.pop(0):
flag *= 1
else:
flag *= 0
else:
while len(a)>1:
if a.pop() == a.pop(0):
flag *= 1
else:
flag *= 0
if flag == 1:
print('yes')
else:
print('no')

5 changes: 5 additions & 0 deletions argorithm/15486.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
input = sys.stdin.readline

N = int(input())
arr =
16 changes: 16 additions & 0 deletions argorithm/2240_gw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys
input = sys.stdin.readline
t, w = map(int, input().split())
A = [int(input()) for _ in range(t)]
dp = [[0]*(t+1) for _ in range(w+1)]

for row in range(w+1):
for col in range(1, t+1):
print(row, col)
c = 1 if A[col - 1] == row % 2 + 1 else 0
if row ==0:
dp[row][col] = dp[row][col-1]+ c
continue
dp[row][col] = max(dp[row-1][col-1], dp[row][col-1]) + c

print(max([row[-1] for row in dp]))

0 comments on commit 365e1bb

Please sign in to comment.