No Rules Rules

Speed Limit (feat. 백준, 14541번) 본문

생활/코테

Speed Limit (feat. 백준, 14541번)

개발하는 완두콩 2022. 9. 8. 16:43
728x90
반응형

Speed Limit
https://www.acmicpc.net/problem/14541

 

14541번: Speed Limit

The input consists of one or more data sets. Each set starts with a line containing an integer n, (1 ≤ n ≤ 10), followed by n pairs of values, one pair per line. The first value in a pair, s, is the speed in miles per hour and the second value, t, is t

www.acmicpc.net

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
using namespace std;
int main(){
    ios::sync_with_stdio(false), cin.tie(NULL);
    register int N, S, T;
    while(1){
        cin >> N;
        if(N == -1)
            break;
        register int ans = 0, t = 0;
        for(register int n = 0; n < N; ++n){
            cin >> S >> T;
            ans += S * (T - t);
            t = T;
        }
        cout << ans << " miles\n";
    }
    return 0;
}
// *&)*@*

 

 

N개의 S, T를 입력받은 경우, Pn = Sn * (Tn - Tm) (m은 n-1) 의 수식이 성립됩니다.

따라서 P1 + P2 + ... + Pn 의 결과를 정답으로 출력하면 됩니다.

 

 

728x90
반응형

'생활 > 코테' 카테고리의 다른 글

Dyslexia (feat. 백준, 8371번)  (0) 2022.09.08
Speed Limit (feat. 백준, 4635번)  (0) 2022.09.08
Ship Selection (feat. 백준, 10180번)  (0) 2022.09.08
꿍의 우주여행 (feat. 백준, 9501번)  (0) 2022.09.08
Atrium (feat. 백준, 20353번)  (0) 2022.09.08
Comments