※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 18154번 문제인 Speeding이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/18154
18154번: Speeding
The first line contains an integer N, the number of photographs taken, with 2 ≤ N ≤ 100. The following N lines each contain two integers ti and di, with 0 ≤ ti ≤ 10 000 and 0 ≤ di ≤ 1 000 000. The first photograph is always taken at time 0 with
www.acmicpc.net
차가 t1 시각에는 d1 위치에, t2 시각에는 d2 위치에 있었다 하자. (t1<t2, d1<d2)
이 때, 평균값의 정리(MVT)에 의해 이 차는 속력이 적어도 (d2-d1)/(t2-t1)이었던 시점이 항상 존재한다.
따라서 각 구간의"(d2-d1)/(t2-t1) 이하의 가장 큰 정수"값들 중 최댓값을 출력하는 것으로 문제를 해결할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int N;
int oldT, oldD;
int ans = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N; N--;
cin >> oldT >> oldD;
while (N--) {
int T, D; cin >> T >> D;
ans = max(ans, (D - oldD) / (T - oldT));
oldT = T, oldD = D;
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26936 // C++] Gourmeten (0) | 2023.01.11 |
---|---|
[BOJ 26943 // C++] Turnering (0) | 2023.01.11 |
[BOJ 24184 // C++] Arabiska (0) | 2023.01.11 |
[BOJ 26948 // C++] Plankan (0) | 2023.01.11 |
[BOJ 26944 // C++] Uppställning (0) | 2023.01.11 |