Skip to content

Commit

Permalink
Merge branch 'main' into 15-oesnuj
Browse files Browse the repository at this point in the history
  • Loading branch information
oesnuj authored Sep 5, 2024
2 parents e9cc332 + e7bb32a commit 2ce8f9f
Show file tree
Hide file tree
Showing 17 changed files with 437 additions and 115 deletions.
Binary file modified .DS_Store
Binary file not shown.
53 changes: 0 additions & 53 deletions oesnuj/DP/2775.cpp

This file was deleted.

1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
| 13μ°¨μ‹œ | 2024.07.28 | DP | [λΆ€λ…€νšŒμž₯이 λ ν…Œμ•Ό](https://www.acmicpc.net/problem/2775) | [#44](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/44) |
| 14μ°¨μ‹œ | 2024.08.05 | ν•΄μ‹œ | [ λ‚˜λŠ”μ•Ό 포켓λͺ¬ λ§ˆμŠ€ν„° μ΄λ‹€μ†œ ](https://www.acmicpc.net/problem/1620) | [#46](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/46) |
| 15μ°¨μ‹œ | 2024.08.10 | 그리디 | [ 주식 ](https://www.acmicpc.net/problem/11501) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/47) |
=======
---
33 changes: 0 additions & 33 deletions oesnuj/μž¬κ·€/1914.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions oesnuj/ν•΄μ‹œ/1620.js

This file was deleted.

Binary file modified pu2rile/.DS_Store
Binary file not shown.
9 changes: 7 additions & 2 deletions pu2rile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1μ°¨μ‹œ | 2024.03.24 | DP | [ν‰λ²”ν•œ λ°°λ‚­](https://www.acmicpc.net/problem/12865) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/3#issue-2205834078)|
| 1μ°¨μ‹œ | 2024.03.24 | 동적 ν”„λ‘œκ·Έλž˜λ° | [ν‰λ²”ν•œ λ°°λ‚­](https://www.acmicpc.net/problem/12865) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/3#issue-2205834078)|
| 2μ°¨μ‹œ | 2024.03.29 | κ΅¬ν˜„ | [OXν€΄μ¦ˆ](https://www.acmicpc.net/problem/8958) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/6#issue-2214931034)|
| 3μ°¨μ‹œ | 2024.04.02 | λ¬Έμžμ—΄ | [ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³](https://www.acmicpc.net/problem/8958) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/10#issue-2220631332)
| 4μ°¨μ‹œ | 2024.04.08 | μŠ€νƒ | [제둜](https://www.acmicpc.net/problem/10773) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/15#issue-2229909173)
Expand All @@ -11,4 +11,9 @@
| 7μ°¨μ‹œ | 2024.05.10 | μ™„μ „ 탐색 μ•Œκ³ λ¦¬μ¦˜ | [μ˜ν™”κ°λ… 숌](https://www.acmicpc.net/problem/1436) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909)
| 8μ°¨μ‹œ | 2024.05.14 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [νŒ”](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384)
| 9μ°¨μ‹œ | 2024.05.27 | κ΅¬ν˜„ | [μ˜€λŠ˜λ„ μ‘Œλ‹€](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288)
| 10μ°¨μ‹œ | 2024.07.11 | μŠ€νƒ | [ν™”ν•™μ‹λŸ‰](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169)
| 10μ°¨μ‹œ | 2024.07.11 | μŠ€νƒ | [ν™”ν•™μ‹λŸ‰](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169)
| 11μ°¨μ‹œ | 2024.07.13 | μš°μ„ μˆœμœ„ 큐 | [κ°•μ˜μ‹€](https://www.acmicpc.net/problem/1374) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/37#issue-2406937336)
| 12μ°¨μ‹œ | 2024.07.23 | 동적 ν”„λ‘œκ·Έλž˜λ° | [1ν•™λ…„](https://www.acmicpc.net/problem/5557) | [#40](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/40)
| 13μ°¨μ‹œ | 2024.07.26 | μŠ€νƒ | [ν›„μœ„ ν‘œκΈ°μ‹](https://www.acmicpc.net/problem/1918) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/43)
| 14μ°¨μ‹œ | 2024.08.05 | 트리 | [이진 탐색 트리](https://www.acmicpc.net/problem/5639) | [#45](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/45)
| 15μ°¨μ‹œ | 2024.08.15 | 트리 | [λ‚˜λ¬΄ νƒˆμΆœ](https://www.acmicpc.net/problem/15900) | [#48](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/48)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
n = int(input())
nums = list(map(int, input().split()))

# dp ν…Œμ΄λΈ” μ΄ˆκΈ°ν™”
dp = [[0] * 21 for _ in range(n)] # 0 이상 20 μ΄ν•˜μΈ μˆ«μžμ΄λ―€λ‘œ 크기가 21인 λ°°μ—΄

# 첫 번째 숫자λ₯Ό dp ν…Œμ΄λΈ”μ— μ΄ˆκΈ°κ°’μœΌλ‘œ μ„€μ •
dp[0][nums[0]] = 1

# dp ν…Œμ΄λΈ” μ±„μš°κΈ°
for i in range(1, n - 1):
for j in range(21):
if dp[i - 1][j]:
if j + nums[i] <= 20: # λ”ν•˜κΈ°
dp[i][j + nums[i]] += dp[i - 1][j]
if j - nums[i] >= 0: # λΉΌκΈ°
dp[i][j - nums[i]] += dp[i - 1][j]

# λ§ˆμ§€λ§‰ 숫자λ₯Ό λͺ©ν‘œ κ°’μœΌλ‘œ λ§Œλ“€ 수 μžˆλŠ” 경우의 수 좜λ ₯
print(dp[n-2][nums[-1]])
Binary file modified pu2rile/μŠ€νƒ/.DS_Store
Binary file not shown.
113 changes: 113 additions & 0 deletions pu2rile/μŠ€νƒ/ν›„μœ„ ν‘œκΈ°μ‹.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_STACK_SIZE 100
#define MAX_TEXT_SIZE 100 // μ€‘μœ„ ν‘œκΈ° μˆ˜μ‹μ˜ μ΅œλŒ€ 길이

typedef char element;

typedef struct {
element data[MAX_STACK_SIZE];
int top;
} StackType;

// μŠ€νƒ μ΄ˆκΈ°ν™” ν•¨μˆ˜
void init_stack(StackType *s) {
s->top = -1;
}

// 곡백 μƒνƒœ κ²€μΆœ ν•¨μˆ˜
int is_empty(StackType *s) {
return (s->top == -1);
}

// 포화 μƒνƒœ κ²€μΆœ ν•¨μˆ˜
int is_full(StackType *s) {
return (s->top == (MAX_STACK_SIZE - 1));
}

// μ‚½μž… ν•¨μˆ˜
void push(StackType *s, element item) {
if (is_full(s)) {
fprintf(stderr, "μŠ€νƒ 포화 μ—λŸ¬\n");
return;
} else {
s->data[++(s->top)] = item;
}
}

// μ‚­μ œ ν•¨μˆ˜
element pop(StackType *s) {
if (is_empty(s)) {
fprintf(stderr, "μŠ€νƒ 곡백 μ—λŸ¬\n");
exit(1);
} else {
return s->data[(s->top)--];
}
}

// μŠ€νƒμ˜ top에 μžˆλŠ” μš”μ†Œλ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜ (μ‚­μ œν•˜μ§€ μ•ŠμŒ)
element peek(StackType *s) {
if (is_empty(s)) {
fprintf(stderr, "μŠ€νƒ 곡백 μ—λŸ¬\n");
exit(1);
} else {
return s->data[s->top];
}
}

// μ—°μ‚°μžμ˜ μš°μ„  μˆœμœ„λ₯Ό λ°˜ν™˜
int prec(char op) {
switch (op) {
case '(': case ')': return 0;
case '+': case '-': return 1;
case '*': case '/': return 2;
}
return -1;
}

// μ€‘μœ„ ν‘œκΈ° μˆ˜μ‹ -> ν›„μœ„ ν‘œκΈ° μˆ˜μ‹
void infix_to_postfix(char exp[]) {
int i = 0;
char ch, top_op;
int len = strlen(exp);
StackType s;

init_stack(&s); // μŠ€νƒ μ΄ˆκΈ°ν™”
for (i = 0; i < len; i++) {
ch = exp[i];
switch (ch) {
case '+': case '-': case '*': case '/': // μ—°μ‚°μž
// μŠ€νƒμ— μžˆλŠ” μ—°μ‚°μžμ˜ μš°μ„ μˆœμœ„κ°€ 더 ν¬κ±°λ‚˜ κ°™μœΌλ©΄ 좜λ ₯
while (!is_empty(&s) && (prec(ch) <= prec(peek(&s))))
printf("%c", pop(&s));
push(&s, ch);
break;
case '(':// μ™Όμͺ½ κ΄„ν˜Έ
push(&s, ch);
break;
case ')':// 였λ₯Έμͺ½ κ΄„ν˜Έ
top_op = pop(&s);
// μ™Όμͺ½ κ΄„ν˜Έλ₯Ό λ§Œλ‚  λ•ŒκΉŒμ§€ 좜λ ₯
while (top_op != '(') {
printf("%c", top_op);
top_op = pop(&s);
}
break;
default: // ν”Όμ—°μ‚°μž
printf("%c", ch);
break;
}
}
while (!is_empty(&s)) // μŠ€νƒμ— μ €μž₯된 μ—°μ‚°μžλ“€ 좜λ ₯
printf("%c", pop(&s));
}

int main(void) {
char s[MAX_TEXT_SIZE];
scanf("%s", s);
infix_to_postfix(s);
printf("\n");
return 0;
}
65 changes: 65 additions & 0 deletions pu2rile/μŠ€νƒ/ν›„μœ„ ν‘œκΈ°μ‹.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
MAX_STACK_SIZE = 100
MAX_EXPR_SIZE = 100

class Stack:
def __init__(self):
self.items = []

def is_empty(self):
return not self.items

def push(self, item):
if len(self.items) >= MAX_STACK_SIZE:
raise OverflowError("μŠ€νƒ 포화 μ—λŸ¬: μ΅œλŒ€ 크기 초과")
self.items.append(item)

def pop(self):
if self.is_empty():
raise IndexError("μŠ€νƒ 곡백 μ—λŸ¬")
return self.items.pop()

def peek(self):
if self.is_empty():
raise IndexError("μŠ€νƒ 곡백 μ—λŸ¬")
return self.items[-1]

def prec(op):
if op in {'+', '-'}:
return 1
elif op in {'*', '/'}:
return 2
else:
return 0

def infix_to_postfix(exp):
if len(exp) > MAX_EXPR_SIZE:
raise ValueError("μˆ˜μ‹ 길이 초과 μ—λŸ¬: μ΅œλŒ€ 길이 초과")

s = Stack()
postfix = []
for ch in exp:
if ch.isalnum(): # ν”Όμ—°μ‚°μž (숫자, 문자 λ“±)
postfix.append(ch)
elif ch == '(':
s.push(ch)
elif ch == ')':
while not s.is_empty() and s.peek() != '(':
postfix.append(s.pop())
s.pop() # '(' 버림
else: # μ—°μ‚°μž
while not s.is_empty() and prec(ch) <= prec(s.peek()):
postfix.append(s.pop())
s.push(ch)

while not s.is_empty(): # μŠ€νƒμ— 남아 μžˆλŠ” λͺ¨λ“  μ—°μ‚°μžλ₯Ό 좜λ ₯
postfix.append(s.pop())

return ''.join(postfix)

def main():
expr = input()
postfix_expr = infix_to_postfix(expr)
print(postfix_expr)

if __name__ == "__main__":
main()
25 changes: 25 additions & 0 deletions pu2rile/μš°μ„ μˆœμœ„ 큐/κ°•μ˜μ‹€.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import heapq
import sys

n = int(sys.stdin.readline())

heap = [] # λͺ¨λ“  κ°•μ˜μ˜ μ‹œμž‘ μ‹œκ°„κ³Ό μ’…λ£Œ μ‹œκ°„μ„ μ €μž₯ν•  μ΅œμ†Œ νž™
q = [] # ν˜„μž¬ μ‚¬μš© 쀑인 κ°•μ˜μ‹€μ˜ μ’…λ£Œ μ‹œκ°„μ„ μ €μž₯ν•  μ΅œμ†Œ νž™

# 주어진 κ°•μ˜ 수만큼 λ°˜λ³΅ν•˜λ©΄μ„œ κ°•μ˜ 정보λ₯Ό μž…λ ₯λ°›μ•„ μ΅œμ†Œ νž™μ— μ €μž₯
for _ in range(n):
num, start, end = map(int, sys.stdin.readline().split())
heapq.heappush(heap, [start, end, num])

# 첫 번째 κ°•μ˜λ₯Ό μ΅œμ†Œ νž™μ—μ„œ κΊΌλ‚΄μ„œ ν•΄λ‹Ή κ°•μ˜μ˜ μ’…λ£Œ μ‹œκ°„μ„ λ‹€λ₯Έ νž™μ— μ €μž₯
start, end, num = heapq.heappop(heap)
heapq.heappush(q, end)

while heap:
start, end, num = heapq.heappop(heap)
# κ°€μž₯ 빨리 λλ‚˜λŠ” κ°•μ˜μ‹€μ˜ μ’…λ£Œ μ‹œκ°„μ΄ ν˜„μž¬ κ°•μ˜μ˜ μ‹œμž‘ μ‹œκ°„λ³΄λ‹€ μž‘κ±°λ‚˜ κ°™μœΌλ©΄ μ’…λ£Œ μ‹œκ°„μ„ μ΅œμ†Œ νž™μ—μ„œ 제거
if q[0] <= start:
heapq.heappop(q)
heapq.heappush(q, end) # ν˜„μž¬ κ°•μ˜μ˜ μ’…λ£Œ μ‹œκ°„μ„ μ΅œμ†Œ νž™μ— μΆ”κ°€

print(len(q)) # μ΅œμ†Œ νž™ q의 크기가 ν•„μš”ν•œ κ°•μ˜μ‹€μ˜ 수
Binary file added pu2rile/트리/.DS_Store
Binary file not shown.
Loading

0 comments on commit 2ce8f9f

Please sign in to comment.