-
20546 기적의 매매법코테 대비 python/백준 2023. 3. 13. 14:51
https://www.acmicpc.net/problem/20546
20546번: 🐜 기적의 매매법 🐜
1월 14일 기준 준현이의 자산이 더 크다면 "BNP"를, 성민이의 자산이 더 크다면 "TIMING"을 출력한다. 둘의 자산이 같다면 "SAMESAME"을 출력한다. 모든 결과 따옴표를 제외하고 출력한다.
www.acmicpc.net
# BOJ_S5_20546_기적의 매매법[2023-03-13] </br> 문제 : https://www.acmicpc.net/problem/20546 <접근법> ``` 1. 조건 메모가 필수 2. 주어진 조건대로 구현 ``` ```python cash = int(input()) stock = list(map(int,input().split())) #준현이 먼저 j_cash = cash #buy and pray 첫날부터 살수있는 만큼 다산다. j_stock = 0 for i in stock: a = j_cash//i j_cash-= i*a j_stock += a bnp = j_cash +j_stock*stock[-1] #성민이 s_cash = cash s_stock = 0 for i in range(10): if stock[i]<stock[i+1] and stock[i+1]<stock[i+2]and stock[i+2]<stock[i+3]: #sell all c = s_stock s_stock -=c s_cash += c*stock[i+3] b = s_cash//stock[i+3] s_stock +=b s_cash -= b*stock[i+3] if stock[i]>stock[i+1] and stock[i+1]>stock[i+2] and stock[i+2]>stock[i+3]: #buy all b = s_cash//stock[i+3] s_stock +=b s_cash -= b*stock[i+3] timing = s_cash +s_stock*stock[-1] if bnp==timing: print("SAMESAME") elif bnp>timing: print("BNP") elif bnp<timing: print("TIMING") ```
'코테 대비 python > 백준' 카테고리의 다른 글
2003 수들의 합 2 (0) 2023.03.20 4396 지뢰찾기 (0) 2023.03.13 1003 피보나치 함수 (1) 2023.03.09 13459 구슬탈출 (0) 2023.03.09 2206 벽 부수고 이동하기 (0) 2023.03.08