지코바) 7월 4째주 문제풀이

상수·2022년 7월 21일
0

11727) 2×n 타일링 2

from sys import stdin

input = stdin.readline

tiling_method = []

n = int(input().rstrip())

for index in range(n+1):
  if index < 2:
    tiling_method.append(index)
  elif index == 2:
    tiling_method.append(index+1)
  else:
    tiling_method.append(tiling_method[index-1] + 2 * tiling_method[index-2])

print(tiling_method[n] % 10007)

2579) 계단 오르기

from sys import stdin
input = stdin.readline

stairs = []
max_scores = []

n = int(input().rstrip())

for index in range(n):
  stairs.append(int(input().rstrip()))

for index in range(n):
  if index == 0:
    max_scores.append(stairs[index])
  elif index == 1:
    max_scores.append(max(stairs[index-1], stairs[index-1] + stairs[index]))
  elif index == 2:
    max_scores.append(max(stairs[index-1] + stairs[index], stairs[index-2] + stairs[index]))
  elif index > 2:
    max_scores.append(max(max_scores[index-2]+ stairs[index], max_scores[index-3] + stairs[index-1] + stairs[index]))

print(max_scores.pop())

10828) 스택

from sys import stdin
input = stdin.readline

class Stack:
  def __init__(self):
    self.stack = []
  def push(self, num):
    self.stack.append(num)
  def pop(self):
    if len(self.stack) > 0:
      print(self.stack.pop())
    else:
      print(-1)
  def top(self):
    if len(self.stack) > 0:
      print(self.stack[-1])
    else:
      print(-1)
  def size(self):
    print(len(self.stack))
  def empty(self):
    print(1 if len(self.stack) == 0 else 0)


n = int(input().rstrip())
stack = Stack()

for index in range(n):
  command = input().rstrip().split()
  if command[0] == 'push':
    stack.push(int(command[1]))
  elif command[0] == 'pop':
    stack.pop()
  elif command[0] == 'top':
    stack.top()
  elif command[0] == 'size':
    stack.size()
  elif command[0] == 'empty':
    stack.empty()

11650) 좌표 정렬하기

from sys import stdin
input = stdin.readline

def heapify(arr, count):
  for index in range(count, -1, -1):
    siftDown(arr, index, count - 1)

def siftDown(arr, start, end):
  root = start
  while True:
    child = (root * 2) + 1
    if child > end:
      break
    if child + 1 <= end and arr[child] < arr[child + 1]:
      child += 1
    if arr[root][0] < arr[child][0] or (arr[root][0] == arr[child][0] and arr[root][1] < arr[child][1]):
      arr[root], arr[child] = arr[child], arr[root]
      root = child
    else:
      break

def heapsort(arr, count):
  heapify(arr, count)
  for index in range(count, 0, -1):
    arr[0], arr[index - 1] = arr[index - 1], arr[0]
    siftDown(arr, 0, index - 1)
    

n = int(input().rstrip())
v = []

for index in range(n):
  x, y = map(int, input().rstrip().split())
  v.append((x, y))

heapsort(v, len(v))

for index in range(n):
  print(v[index][0], v[index][1])
profile
Dart와 TypeScript를 다룹니다.

0개의 댓글