Skip to content

202102649 서은서 #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions 202102649/10026-적록색약.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

n = int(input().rstrip())
matrix = [list(input().rstrip()) for _ in range(n)]
visited = [[False] * n for _ in range(n)]

three_cnt, two_cnt = 0, 0
dx = [-1,1,0,0]
dy = [0,0,-1,1]

def dfs(x,y):
visited[x][y] = True
current_color = matrix[x][y]

for k in range(4):
nx = x + dx[k]
ny = y + dy[k]
if (0 <= nx < n) and (0 <= ny < n):
if visited[nx][ny]==False:
if matrix[nx][ny] == current_color:
dfs(nx,ny)

for i in range(n):
for j in range(n):
if visited[i][j]==False:
dfs(i,j)
three_cnt += 1

for i in range(n):
for j in range(n):
if matrix[i][j]=='R':
matrix[i][j]='G'

visited = [[False] * n for _ in range(n)]

for i in range(n):
for j in range(n):
if visited[i][j] == False:
dfs(i,j)
two_cnt += 1

print(three_cnt,two_cnt)
7 changes: 7 additions & 0 deletions 202102649/1003-피보나치함수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
T = int(input())
for _ in range(T):
N = int(input())
a, b = 1, 0
for i in range(N):
a, b = b, a + b
print(a, b)
29 changes: 29 additions & 0 deletions 202102649/1167-트리의지름.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n = int(input())
graph = [[] for _ in range(n+1)]

for _ in range(n):
node = list(map(int, input().split()))[:-1]
for i in range(1, len(node)//2 + 1):
graph[node[0]].append([node[i*2 - 1], node[i*2]])

def dfs(x, dist):
for i in graph[x]:
node, wei = i
if distance[node] == -1:
distance[node] = dist + wei
dfs(node, dist + wei)

distance = [-1] * (n+1)
distance[1] = 0
dfs(1, 0)

res = distance.index(max(distance))
distance = [-1] * (n+1)
distance[res] = 0
dfs(res, 0)

print(max(distance))
Empty file added 202102649/1463-1로만들기.py
Empty file.
23 changes: 23 additions & 0 deletions 202102649/1655-가운데를말해요.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import heapq
import sys

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

leftHeap = []
rightHeap = []
for i in range(n):
num = int(sys.stdin.readline())

if len(leftHeap) == len(rightHeap):
heapq.heappush(leftHeap, -num)
else:
heapq.heappush(rightHeap, num)

if rightHeap and rightHeap[0] < -leftHeap[0]:
leftValue = heapq.heappop(leftHeap)
rightValue = heapq.heappop(rightHeap)

heapq.heappush(leftHeap, -rightValue)
heapq.heappush(rightHeap, -leftValue)

print(-leftHeap[0])
Empty file added 202102649/17298-오큰수.py
Empty file.
24 changes: 24 additions & 0 deletions 202102649/1918-후위표기식.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
strn = list(input())
stack=[]
res=''
for s in strn:
if s.isalpha():
res+=s
else:
if s == '(':
stack.append(s)
elif s == '*' or s == '/':
while stack and (stack[-1] == '*' or stack[-1] =='/'):
res += stack.pop()
stack.append(s)
elif s == '+' or s == '-':
while stack and stack[-1] != '(':
res+= stack.pop()
stack.append(s)
elif s == ')':
while stack and stack[-1] != '(':
res += stack.pop()
stack.pop()
while stack :
res+=stack.pop()
print(res)
66 changes: 66 additions & 0 deletions 202102649/7569-토마토.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <iostream>
#include <vector>
#include <queue>

using namespace std;


int m, n, h, ans, dist[102][102][102];
int dx[] = {0,0,1,-1,0,0};
int dy[] = {1,-1,0,0,0,0};
int dz[] = {0,0,0,0,1,-1};
queue<pair<pair<int,int>, int>> q;

void bfs(){
while(!q.empty()){
int xx = q.front().first.first;
int yy = q.front().first.second;
int zz = q.front().second;
q.pop();
for(int i=0;i<6;i++){
int nx = xx+dx[i];
int ny = yy+dy[i];
int nz = zz+dz[i];

if(nx>=0&&ny>=0&&nz>=0&&nx<n&&ny<m&&nz<h&&dist[nx][ny][nz] == 0){
dist[nx][ny][nz] = dist[xx][yy][zz] + 1;
q.push(make_pair(make_pair(nx,ny),nz));
}
}
}

}
int main()
{
cin >> m >> n >> h;
for(int k=0;k<h;k++){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin >> dist[i][j][k];
if(dist[i][j][k] == 1){
q.push(make_pair(make_pair(i,j),k));
}
}
}
}

bfs();

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for(int k=0;k<h;k++){
if (dist[i][j][k] == 0) {
cout << -1;
return 0;
}else {
ans = max(dist[i][j][k], ans);
}
}

}
}

cout << ans-1;

return 0;
}
67 changes: 67 additions & 0 deletions 202102649/7576-토마토.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <iostream>
#include <queue>

using namespace std;

int tomatoMap[1000][1000];
queue<pair<int, int>> q;
int result = 0;
int M, N;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void tomatoBFS() {
while (!q.empty()) {
int xx = q.front().first;
int yy = q.front().second;

q.pop();

for (int i = 0; i < 4; i++) {
int nx = xx + dx[i];
int ny = yy + dy[i];

if (nx >= 0 && ny >= 0 && nx < N && ny < M) {
if (tomatoMap[nx][ny] == 0) {
tomatoMap[nx][ny] = tomatoMap[xx][yy] + 1;
q.push(make_pair(nx, ny));
}
}
}
}
}

void tomato() {
cin >> M >> N;

for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> tomatoMap[i][j];

if (tomatoMap[i][j] == 1) {
q.push(make_pair(i, j));
}
}
}
tomatoBFS();


for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (tomatoMap[i][j] == 0) {
cout << -1 << "\n";
return;
}

if (result < tomatoMap[i][j]) {
result = tomatoMap[i][j];
}
}
}

cout << result - 1 << "\n";
}
int main() {
tomato();

return 0;
}
17 changes: 17 additions & 0 deletions 202102649/9095-123더하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
input = sys.stdin.readline

def func(x):
if x == 1:
return 1
elif x == 2:
return 2
elif x == 3:
return 4
else:
return func(x - 1) + func(x - 2) + func(x - 3)

t = int(input())
for _ in range(t):
n = int(input())
print(func(n))