반응형
1712 손익분기점
A,B,C = map(int, input().split())
if B >=C:
print("-1")
else:
result = A//(C-B) + 1
print(result)
핵심 : A//C-B
1193 분수찾기
n = int(input())
count = 1
while count < n:
n-=count
count+=1
if count%2==0:
down = count-n+1
up = n
else:
down = n
up = count-n+1
print(up,"/",down,sep="")
해당 수의 라인의 찾고 ( 라인은 1씩 증가 ex 1, 2, 3, . .. )
분모 분자의 특징 찾기. ( 분모 분자가 라인의 짝수 홀수에 따라 반대)
2869 달팽이는 올라가고 싶다
1. 시간초과
A, B, V = map(int,input().split())
day = 0
dist = 0
while True:
day+=1
dist +=A
if dist == V:
break
dist-=B
print(day)
2. 식을 구현하기 힘들다..
출처 https://zifmfmphantom.tistory.com/75
import math
A, B, V = map(int,input().split())
print(math.ceil((V-A)/(A-B)+1))
10250 ACM 호텔
1. 실패
T = int(input())
for i in range(T):
H,W,N = map(int,input().split())
XX = N//H+1
YY = N%H
print(YY,str(XX).zfill(2),sep="")
2. N%H==0 일 경우(꼭대기 층) 처리해줌
T = int(input())
for i in range(T):
H,W,N = map(int,input().split())
if N%H==0:
YY = H #층
XX = N//H #호수
else:
XX = N//H+1
YY = N%H
print(YY,str(XX).zfill(2),sep="")
zfill함수는 빈칸을 0으로 채워주는 함수.
호수가 하나일 경우 채워줘야함
2775 부녀회장
T = int(input())
for i in range(T):
k = int(input()) #층
n = int(input()) #호
karr = [x for x in range(1,n+1)] #0층 리스트
for i in range(k): #0층 ~ k-1층
for j in range(1,n): # 1호실 ~ n호실
karr[j] +=karr[j-1] # 아래층 + 이전호수 = 현재
print(karr[-1])
이런 문제도 한 번에 풀 수가 없다 ..
리스트에 반복해서 층수의 값을 구한다.
현재층 호수의 인원수 = 이전 층의 호수 + 이전 호수
ex) 2층 3호 = 1층 3호 + 2층 2호
2839 설탕배달
맞아서 좋아했지만 다른 사람의 풀이를 보고 다시 기분이 안 좋아졌다.
N = int(input())
count = 0
while N!=0:
if N<5 and N!=3: #5보다 작은데 3이 아닌 경우
count = -1
break
if N%3==0 and N%5!=0: #3으로만 나눠지는 경우
N-=3
count +=1
elif N%5==0: # 5로만 나눠지는 경우
count += N//5
break
else: # 둘다 아닌 경우
N = N-5
count +=1
print(count)
다른 사람풀이
출처 https://ooyoung.tistory.com/81
1011 Fly me to the Alpha Centauri
count 가 증가 할때마다 거리는 1,1,2,2,3,3 이런식으로 증가된다.
출처 https://ooyoung.tistory.com/91
T = int(input())
for i in range(T):
x,y = map(int, input().split())
dist = y-x
k = 1
count = 0
move_dist = 0
while move_dist < dist:
count +=1
move_dist+=k
if count %2 ==0:
k +=1
print(count)
반복규칙을 찾는 문제.
수학적 원리가 있는 줄 알았는데 결국 거리가 1일때 부터 늘려가다 보면 반복패턴이 나온다.
반응형
'코딩테스트 > 백준 준비(과거)' 카테고리의 다른 글
(파이썬) 백준 1978, 2581, 11653, 1929, 4948, 9020, 1085, 3009, 4153 (0) | 2021.07.07 |
---|---|
(파이썬) 백준 11654, 11720, 10809, 2675, 1157, 1152, 2908, 5622, 2941, 1316 (0) | 2021.06.27 |
(파이썬) 백준 4673, 1065 (0) | 2021.06.26 |
(파이썬) 백준 10818, 2562, 2577, 3052, 1546, 8958, 4344 (0) | 2021.06.26 |
(파이썬) 백준 2739, 15552, 11022, 2439, 10871, 10952, 1110 (0) | 2021.06.24 |
댓글