Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnadi4 committed Dec 11, 2022
2 parents babe6b4 + 4614269 commit 51d311e
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 마라/6주차/1725_히스토그램.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
n =int(input())
heights = []
for _ in range(n) :
heights.append(int(input()))


def maxSize():
max_size = 0
stack = []

for i in range(n):
left = i
#Stack 가장 위 값보다 작은 값이 들어올 경우
while stack and stack[-1][0] >= heights[i]:
#가장 위 기둥을 pop 하고
h, left = stack.pop()
#넓이를 계산해서
tmp_size = h * (i - left)
#max size를 계산하여 업데이트한다
max_size = max(max_size, tmp_size)
#스택의 위 값보다 큰 값이 들어올경우
#스택의 높이와 왼쪽 좌표를 스택에 담는다
stack.append([heights[i],left])

#스택에 남아있는 값들을 가장 오른쪽 좌표(n) 기준으로 계산
for h, point in stack:
max_size = max(max_size, (n-point)*h)

return max_size
print(maxSize())
37 changes: 37 additions & 0 deletions 마라/6주차/2304_창고다각형.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
N = int(input())

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

lst.sort(key=lambda x : x[0])
#가장 큰 박스의 왼쪽 , 오른쪽 좌표 구하기
left = lst[0][0]
right = lst[N-1][0]

lst.sort(key=lambda x : -x[1])
#가장 긴 애 길이
tall = lst[0][1]

#가장 큰 박스 넓이
width = (right - left +1) * lst[0][1]

#왼쪽 기준, 오른쪽 기준 위치
left_std = lst[0][0]
right_std =lst[0][0]

for L , H in lst:
#기준 사이에 있으면 넘어감
if L >= left_std and L <= right_std :
continue
#기준 밖에 있으면 넓이 감소
else :
if L < left_std:
width -= (left_std - L) * (tall - H)

left_std = L
if L > right_std :
width -= ( L - right_std) * (tall - H)

right_std = L
print(width)
45 changes: 45 additions & 0 deletions 마라/6주차/5076_webpages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

stack = []

#string이 legal 한지 계산하는함수
def isLegal(string) :
for i in range(len(string)) :
if string[i] == '<' :
for j in range(i + 1 , len(string)) :
if string[j] == '>' :
#스택에 넣기
stacking(string[i+1 : j])
break
#스택에 남아있는경우 요소가 닫히지 않았단 뜻이므로 illegal 출력
if len(stack) != 0:
return False
return True


#stack에 요소(ex)</string> 를 넣는 함수
def stacking(item) :
if item[0] == "a":
stack.append(item[0])
return True
if item =="br /" :
return True
if len(stack) == 0:
stack.append(item)
return True
top = stack[-1]
if "/" + top == item :
stack.pop()
return True
stack.append(item)
return True


while True:
line = input()
stack = []
if line == "#" :
break
if isLegal(line) :
print("legal")
else :
print("illegal")
45 changes: 45 additions & 0 deletions 와우/5주차/이분탐색_BJ15732_도토리숨기기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.util.*;

class Main {

static class Box {
int start;
int end;
int unit;

Box(int start, int end, int unit) {
this.start = start;
this.end = end;
this.unit = unit;
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
int k = sc.nextInt();
int d = sc.nextInt();
ArrayList<Box> box = new ArrayList<Box>();

for(int i=0; i<k; i++)
box.add(new Box(sc.nextInt(), sc.nextInt(), sc.nextInt()));

int left = 1;
int right = n;
while(left <= right) {
int mid = (left + right)/2;
long cnt = 0;
for(int i=0; i<box.size(); i++) {
if(box.get(i).end <= mid)
cnt += (box.get(i).end - box.get(i).start)/box.get(i).unit + 1;
else if(box.get(i).start > mid) continue;
else
cnt += (mid - box.get(i).start) == 0 ? 1 : (mid - box.get(i).start)/box.get(i).unit + 1;
}
if(cnt >= d) right = mid - 1;
else left = mid + 1;
}
System.out.println(left);
}
}
32 changes: 32 additions & 0 deletions 우기/6주차/2304_창고다각형.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys

n = int(sys.stdin.readline().rstrip())
info = []
max_info = (-1, -1)
for _ in range(n):
x, h = map(int, sys.stdin.readline().rstrip().split())
if h > max_info[1]:
max_info = (x, h)
info.append((x, h))

length = max(info, key=lambda item: item[0])[0] + 1

arr = [0] * length
for x, h in info:
arr[x] = h

last_h = -1
for i in range(1, length):
if i == max_info[0]:
break
last_h = max(arr[i], last_h)
arr[i] = last_h

last_h = -1
for i in range(length - 1, 0, -1):
if i == max_info[0]:
break
last_h = max(arr[i], last_h)
arr[i] = last_h

print(sum(arr))
59 changes: 59 additions & 0 deletions 우기/6주차/5076_WebPages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sys

OPEN = 0
CLOSE = 1


def parse(html):
idx = 0
tags = []
while True:
if idx >= len(html):
break

# 태그 시작
if html[idx] == '<':
flag = OPEN
idx += 1

# 닫는 태그인 경우
if html[idx] == '/':
flag = CLOSE
idx += 1

# 태그 읽기
tag = ""
while html[idx] != '>' and idx < len(html):
# 단일 태그인 경우
if idx < len(html) - 1 and html[idx] == '/' and html[idx + 1] == '>':
tag = ""
break

tag += html[idx]
idx += 1

if tag:
tags.append((flag, tag.split()[0]))
idx += 1

ans = "legal"
stack = []
for flag, tag in tags:
if flag == OPEN:
stack.append(tag)
else:
if stack and tag == stack[-1]:
stack.pop()
else:
ans = "illegal"
break
if stack:
ans = "illegal"
print(ans)


while True:
s = sys.stdin.readline().rstrip()
if s == "#":
break
parse(s)

0 comments on commit 51d311e

Please sign in to comment.