From 12d35b276df74f7ba48ab1b51070ee8517c392af Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Mon, 4 Nov 2024 13:36:14 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Solve]:9=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[BOJ[17281-\354\225\274\352\265\254.py" | 66 ++++++++ ...4\353\246\254 \354\241\260\354\236\221.py" | 48 ++++++ ...4 \354\234\267\353\206\200\354\235\264.py" | 145 ++++++++++++++++++ momnpa333/week8/16928.py | 38 +++++ momnpa333/week8/2156.py | 23 +++ momnpa333/week8/23288.py | 85 ++++++++++ momnpa333/week9/1806.py | 23 +++ momnpa333/week9/2138.py | 53 +++++++ 8 files changed, 481 insertions(+) create mode 100644 "momnpa333/week7/[BOJ[17281-\354\225\274\352\265\254.py" create mode 100644 "momnpa333/week7/[BOJ]15684-\354\202\254\353\213\244\353\246\254 \354\241\260\354\236\221.py" create mode 100644 "momnpa333/week7/[BOJ]17825-\354\243\274\354\202\254\354\234\204 \354\234\267\353\206\200\354\235\264.py" create mode 100644 momnpa333/week8/16928.py create mode 100644 momnpa333/week8/2156.py create mode 100644 momnpa333/week8/23288.py create mode 100644 momnpa333/week9/1806.py create mode 100644 momnpa333/week9/2138.py diff --git "a/momnpa333/week7/[BOJ[17281-\354\225\274\352\265\254.py" "b/momnpa333/week7/[BOJ[17281-\354\225\274\352\265\254.py" new file mode 100644 index 0000000..34d3b8f --- /dev/null +++ "b/momnpa333/week7/[BOJ[17281-\354\225\274\352\265\254.py" @@ -0,0 +1,66 @@ +import sys +from itertools import permutations +from collections import deque +input=sys.stdin.readline + +N=int(input()) + +hit_info=[list(map(int,input().split())) for _ in range(N)] + +# def play_game(sequence,N): +# score=0 +# sequence=sequence[0:3]+[0]+sequence[3:] +# cur_attacker=0 +# for base in range(N): +# base_status=[] +# out_count=0 +# while out_count<3: +# if hit_info[base][sequence[cur_attacker]]==0: +# out_count+=1 +# cur_attacker=(cur_attacker+1)%9 +# continue +# runner = [0]*hit_info[base][sequence[cur_attacker]] +# runner[-1]=1 +# base_status=runner+base_status +# cur_attacker=(cur_attacker+1)%9 +# score+=sum(base_status[3:]) +# base_status=base_status[:3] +# return score + +def play_game2(sequence,N): + score=0 + sequence=sequence[0:3]+[0]+sequence[3:] + cur_attacker=0 + for base in range(N): + out_count=0 + base_1=0; base_2=0; base_3=0 + while out_count<3: + if hit_info[base][sequence[cur_attacker]]==0: + out_count+=1 + elif hit_info[base][sequence[cur_attacker]]==1: + score+=base_3 + base_1, base_2, base_3 = 1,base_1,base_2 + elif hit_info[base][sequence[cur_attacker]]==2: + score+=(base_2+base_3) + base_1,base_2,base_3=0,1,base_1 + elif hit_info[base][sequence[cur_attacker]]==3: + score+=(base_1+base_2+base_3) + base_1,base_2,base_3=0,0,1 + elif hit_info[base][sequence[cur_attacker]]==4: + score+=(1+base_1+base_2+base_3) + base_1=0; base_2=0; base_3=0 + + cur_attacker=(cur_attacker+1)%9 + return score + + +answer=0 + +# print(play_game2([4,5,6,1,2,3,4,5],N)) + +for sequence in permutations(range(1,9)): + score = play_game2(list(sequence),N) + if answer25 :A +#20->25: B +#30->25: C +#25->40: D +#그외 :S +Sboard=[[i,True] for i in range(0,40,2)] +Aboard=[[i,True] for i in range(10,22,3)] +Bboard=[[i,True] for i in range(20,26,2)] +Cboard=[[i,True] for i in range(28,25,-1)] +Dboard=[[i,True] for i in range(25,45,5)] + +#말->W,X,Y,Z +total_score={ + "W":0, + "X":0, + "Y":0, + "Z":0 +} + +def move_horse(horse,position,dice,total_score,Sboard,Aboard,Bboard,Cboard,Dboard): + if position[0]=="S": + if dice+position[1]>20: + Sboard[dice+position[1]][1]=True + return ("EXIT",total_score) + if dice+position[1]==5 and Aboard[0][1]==True: + total_score[horse]+=Aboard[0][0] + Sboard[position[1]][1]=True + Aboard[0][1]=False + return ("A",0,total_score) + if dice+position[1]==10 and Bboard[0][1]==True: + total_score[horse]+=Aboard[0][0] + Sboard[position[1]][1]=True + Bboard[0][1]=False + return ("B",0,total_score) + if dice+position[1]==15 and Cboard[0][1]==True: + total_score[horse]+=Aboard[0][0] + Sboard[position[1]][1]=True + Cboard[0][1]=False + return ("C",0,total_score) + if dice+position[1]==20 and Dboard[3][1]==True: + total_score[horse]+=Dboard[3][0] + Sboard[position[1]][1]=True + Dboard[3][1]=False + return ("D",3,total_score) + if Sboard[dice+position[1]][1]==True: + total_score[horse]+=Sboard[dice+position[1]][0] + Sboard[position[1]][1]=True + Sboard[dice+position[1]][1]=False + return ("S",dice+position[1],total_score) + return ("S",position[1],total_score) + if position[0]=="A": + next_position=dice+position[1] + if next_position>7: + Aboard[position[1]]=True + return ("EXIT",total_score) + if next_position>3: + next_position-=4 + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Aboard[position[1]][1]=True + return ("D",next_position,total_score) + if Aboard[next_position][1]==True: + total_score[horse]+=Aboard[next_position][0] + Aboard[next_position][1]=False + Aboard[position[1]]=True + return ("A",next_position,total_score) + if position[0]=="B": + next_position=dice+position[1] + if next_position>6: + Bboard[position[1]]=True + return ("EXIT",total_score) + if next_position>2: + next_position-=3 + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Bboard[position[1]][1]=True + return ("D",next_position,total_score) + if Bboard[next_position][1]==True: + total_score[horse]+=Bboard[next_position][0] + Bboard[next_position][1]=False + Bboard[position[1]]=True + return ("B",next_position,total_score) + if position[0]=="C": + next_position=dice+position[1] + if next_position>7: + Cboard[position[1]]=True + return ("EXIT",total_score) + if next_position>3: + next_position-=4 + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Cboard[position[1]][1]=True + return ("D",next_position,total_score) + if Cboard[next_position][1]==True: + total_score[horse]+=Cboard[next_position][0] + Cboard[next_position][1]=False + Cboard[position[1]]=True + return ("C",next_position,total_score) + if position[0]=="D": + next_position=dice+position[1] + if next_position>3: + Dboard[position[1]]=True + return ("EXIT",total_score) + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Dboard[position[1]]=True + return ("D",next_position,total_score) + return (position[0],position[1],total_score) + + +dq=deque([]) +dq.appendleft(({"W":("S",0),"X":("S",0),"Y":("S",0),"Z":("S",0)},total_score.copy(),copy.deepcopy(Sboard),copy.deepcopy(Aboard),copy.deepcopy(Bboard),copy.deepcopy(Cboard),copy.deepcopy(Dboard))) +round=0 +while dq: + if round==1: + break + for _ in range(len(dq)): + horses,total_score,Sboard,Aboard,Bboard,Cboard,Dboard=dq.popleft() + for horse in horses: + result=move_horse(horse,horses[horse],rolls[round],total_score,Sboard,Aboard,Bboard,Cboard,Dboard) + horse_status=horses.copy() + if result[0]=="EXIT": + del horse_status[horse] + dq.appendleft((horse_status,result[1],copy.deepcopy(Sboard),copy.deepcopy(Aboard),copy.deepcopy(Bboard),copy.deepcopy(Cboard),copy.deepcopy(Dboard))) + continue + horse_status[horse]=(result[0],result[1]) + dq.appendleft(((horse_status),result[2],copy.deepcopy(Sboard),copy.deepcopy(Aboard),copy.deepcopy(Bboard),copy.deepcopy(Cboard),copy.deepcopy(Dboard))) + round+=1 + +for item in dq: + print(item[0],item[1]) + + + diff --git a/momnpa333/week8/16928.py b/momnpa333/week8/16928.py new file mode 100644 index 0000000..279bb68 --- /dev/null +++ b/momnpa333/week8/16928.py @@ -0,0 +1,38 @@ +#100번 칸을 넘어간다면 이동할 수 없다. +#도착한 칸이 사다리면, 사다리를 타고 위로 올라간다. 뱀이 있는 칸에 도착하면, 뱀을 따라서 내려가게 된다. +#1번 칸과 100번 칸은 뱀과 사다리의 시작 또는 끝이 아니다. 모든 칸은 최대 하나의 사다리 또는 뱀을 가지고 있으며, 동시에 두 가지를 모두 가지고 있는 경우는 없다. 항상 100번 칸에 도착할 수 있는 입력만 주어진다. + +import sys +from collections import deque +input=sys.stdin.readline + +N,M=map(int,input().split()) +bridge=dict() +for _ in range(N+M): + u,v=map(int,input().split()) + bridge[u]=v + +dq=deque([]) +position=1 +check={1,} + +dq.append(1) + +count=0 + +while dq: + count+=1 + for _ in range(len(dq)): + pos=dq.popleft() + for i in range(1,7): + next=pos+i + if next in bridge: + next=bridge[next] + if next==100: + print(count) + exit(0) + if next<=100 and next not in check: + dq.append(next) + check.add(next) + + diff --git a/momnpa333/week8/2156.py b/momnpa333/week8/2156.py new file mode 100644 index 0000000..a555d4b --- /dev/null +++ b/momnpa333/week8/2156.py @@ -0,0 +1,23 @@ +import sys +input=sys.stdin.readline + +N=int(input()) + +wine=[] +for _ in range(N): + wine.append(int(input())) + +if N<3: + print(sum(wine)) + exit(0) + +dp=[0]*N + +dp[0]=wine[0] +dp[1]=dp[0]+wine[1] +dp[2]=max(dp[1],dp[0]+wine[2],wine[1]+wine[2]) + +for i in range(3,N): + dp[i]=max(dp[i-1],dp[i-2]+wine[i],dp[i-3]+wine[i-1]+wine[i]) + +print(dp[-1]) \ No newline at end of file diff --git a/momnpa333/week8/23288.py b/momnpa333/week8/23288.py new file mode 100644 index 0000000..dac9ee6 --- /dev/null +++ b/momnpa333/week8/23288.py @@ -0,0 +1,85 @@ +import sys +from collections import deque +input=sys.stdin.readline + +N,M,K=map(int,input().split()) +board=[list(map(int,input().split())) for _ in range(N)] + +diceRow=[2,1,5,6] +diceCol=[4,1,3,6] + +dir_dict={0:(0,1),1:(1,0),2:(0,-1),3:(-1,0)} + +def move_dice(op): + global diceCol + global diceRow + + if op==0: + diceCol=[diceCol[-1]]+diceCol[:3] + diceRow[-1]=diceCol[-1];diceRow[1]=diceCol[1] + elif op==1: + diceRow=[diceRow[-1]]+diceRow[:3] + diceCol[-1]=diceRow[-1];diceCol[1]=diceRow[1] + elif op==2: + diceCol=diceCol[1:]+[diceCol[0]] + diceRow[-1]=diceCol[-1];diceRow[1]=diceCol[1] + elif op==3: + diceRow=diceRow[1:]+[diceRow[0]] + diceCol[-1]=diceRow[-1];diceCol[1]=diceRow[1] + +def make_score_board(board): + scored_board=[[-1]*M for _ in range(N)] + dq=deque([]) + + + for r in range(N): + for c in range(M): + fill_position=[] + if scored_board[r][c]==-1: + fill_position.append((r,c)) + dq.appendleft((r,c,board[r][c])) + scored_board[r][c]=0 + cnt=1 + while dq: + for _ in range(len(dq)): + curR,curC,score=dq.popleft() + for addR,addC in ((0,1),(1,0),(0,-1),(-1,0)): + R=curR+addR;C=curC+addC + if 0<=Rboard[R][C]: + dir=(dir+1)%4 + elif diceRow[3]=S: + if right-left+1count: + answer=count + return + if on_lights==target: + if answer>count+1: + answer=count+1 + return + + if 1 Date: Fri, 8 Nov 2024 20:49:59 +0900 Subject: [PATCH 2/3] Solve:[BOJ]1043 --- ...3-\352\261\260\354\247\223\353\247\220.py" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" diff --git "a/momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" "b/momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" new file mode 100644 index 0000000..83a874b --- /dev/null +++ "b/momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" @@ -0,0 +1,49 @@ +import sys +input=sys.stdin.readline + +N,M=map(int,input().split()) +lier=set(list(map(int,input().split()))[1:]) + +parents=[i for i in range(N+1)] + +groups=[] + +def findparents(i): + if i!=parents[i]: + parents[i]=findparents(parents[i]) + return parents[i] + return i + +def union(a,b): + a=findparents(a) + b=findparents(b) + if a in lier or b in lier: + lier.add(a) + lier.add(b) + + if a Date: Fri, 8 Nov 2024 20:50:09 +0900 Subject: [PATCH 3/3] Solve:[BOJ]1149 --- .../[BOJ]1149-RGB\352\261\260\353\246\254.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "momnpa333/week10/[BOJ]1149-RGB\352\261\260\353\246\254.py" diff --git "a/momnpa333/week10/[BOJ]1149-RGB\352\261\260\353\246\254.py" "b/momnpa333/week10/[BOJ]1149-RGB\352\261\260\353\246\254.py" new file mode 100644 index 0000000..5047869 --- /dev/null +++ "b/momnpa333/week10/[BOJ]1149-RGB\352\261\260\353\246\254.py" @@ -0,0 +1,17 @@ +N=int(input()) +cost=[] +for _ in range(N): + cost.append(list(map(int,input().split()))) + +dp=[[0]*N for _ in range(3)] + +dp[0][0]=cost[0][0] +dp[1][0]=cost[0][1] +dp[2][0]=cost[0][2] + +for i in range(1,N): + dp[0][i]=min(dp[1][i-1]+cost[i][0],dp[2][i-1]+cost[i][0]) + dp[1][i]=min(dp[0][i-1]+cost[i][1],dp[2][i-1]+cost[i][1]) + dp[2][i]=min(dp[0][i-1]+cost[i][2],dp[1][i-1]+cost[i][2]) +else: + print(min(dp[0][N-1],dp[1][N-1],dp[2][N-1]))