728x90
https://www.acmicpc.net/problem/13458
13458번: 시험 감독
첫째 줄에 시험장의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 각 시험장에 있는 응시자의 수 Ai (1 ≤ Ai ≤ 1,000,000)가 주어진다. 셋째 줄에는 B와 C가 주어진다. (1 ≤ B, C ≤ 1,000,000)
www.acmicpc.net
<처음 만든 코드>
n = int(input())
arr = list(map(int,input().split()))
b,c = map(int,input().split())
cnt = 0
max_super = max(b,c)
min_super = min(b,c)
for student in arr :
while True :
if student == 0 : break
if student > max_super :
cnt += student // max_super
student = student % max_super
elif student > min_super :
cnt += student // min_super
student = student % min_super
else :
cnt += 1
student = 0
print(cnt)
주어진 예시는 모두 맞으나
각각의 시험장에 총감독관은 오직 1명만 있어야 하고,
이 부분을 생각하지 못했다.
max와 min을 구분할 필요가 없었다!
<그 다음 만든 코드>
n = int(input())
arr = list(map(int,input().split()))
b,c = map(int,input().split())
cnt = 0
for student in arr :
cnt+=1
if student < b : # 감독 한명으로 충분
cnt += 1
continue
else :
if (student-b) % c == 0 :
cnt += (student-b) // c
else :
cnt += (student-b) // c
cnt += 1
print(cnt)
이번에도 나와있는 예시는 모두 맞지만 틀렸습니다가 나온다.
영 모르겠고 잠은 오고 나와있는 input은 계속 맞으니
생각의 힘이 떨어져 카톡방에 질문했다.
<정답 코드>
n = int(input())
arr = list(map(int,input().split()))
b,c = map(int,input().split())
cnt = 0
for student in arr :
cnt+=1
if student <= b : # 감독 한명으로 충분 # =을 추가
continue
else :
if (student-b) % c == 0 :
cnt += (student-b) // c
else :
cnt += (student-b) // c
cnt += 1
print(cnt)
그 이유는 if student <= b : 에서 cnt+=1 을 했기 때문이었다.
이미 그 전에 기본적으로 cnt+=1 이 더해지기 때문에 student가 b보다 작거나 같을 경우에는 cnt+=1을 할 필요가 없다!
하하 이 문제는 브론즈 문제라 쉬울것이라 예상하고 풀었는데
실제로 쉬웠다.
약간의 실수를 해서 아쉽지만 풀이를 보지않고 풀었다는것에 기분이 좋다.
<20220629>
미래의 내가 푼 풀이 :
n = int(input())
arr = list(map(int,input().split()))
b,c = map(int,input().split())
answer = len(arr)
for i in arr :
if i - b > 0 :
if (i-b)%c == 0 :
answer += (i-b) // c
else :
answer += ((i-b)//c) + 1
print(answer)
마지막 부분을 한줄로 만들 수도 있다.
if __name__=="__main__" :
n = int(input())
student = list(map(int,input().split()))
b,c = map(int,input().split())
ans = n
for i in student:
if i-b >0 :
ans += (i-b)//c +1 if (i-b)%c!=0 else (i-b)//c
print(ans )
반응형
'알고리즘 > 백준 문제풀이' 카테고리의 다른 글
[삼성SW역량][Python/BOJ] 백준 14501 퇴사(DFS) (0) | 2022.06.29 |
---|---|
[삼성SW역량][Python/BOJ] 백준 14500 테트로미노(DFS) (0) | 2022.06.29 |
[Python/BOJ] 백준 1753 최단경로(다익스트라) (0) | 2022.01.16 |
[Python/BOJ] 백준 14442 벽 부수고 이동하기2(BFS)-시간초과에서 삽질하다가 AC (3) | 2022.01.14 |
[Python/BOJ] 백준 2206 벽 부수고 이동하기(BFS) (0) | 2022.01.13 |