poj 2017 Speed Limit

Speed Limit

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 17704   Accepted: 12435

Description

Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don‘t know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time they have driven. Unfortunately, their record keeping strategy is a little odd, so they need help computing the total distance driven. You are to write a program to do this computation.

For example, if their log shows

Speed in miles perhour Total elapsed time in hours
20 2
30 6
10 7

this means they drove 2 hours at 20 miles per hour, then 6-2=4 hours at 30 miles per hour, then 7-6=1 hour at 10 miles per hour. The distance driven is then (2)(20) + (4)(30) + (1)(10) = 40 + 120 + 10 = 170 miles. Note that the total elapsed time is always since the beginning of the trip, not since the previous entry in their log.

Input

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 the total elapsed time. Both s and t are integers, 1 <= s <= 90 and 1 <= t <= 12. The values for t are always in strictly increasing order. A value of -1 for n signals the end of the input.

Output

For each input set, print the distance driven, followed by a space, followed by the word "miles"

Sample Input

3
20 2
30 6
10 7
2
60 1
30 5
4
15 1
25 2
30 3
10 5
-1

Sample Output

170 miles
180 miles
90 miles

Source

Mid-Central USA 2004

分析:

 1 #include <cstdio>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<string>
 5 #include<cstring>
 6 #include<vector>
 7 using namespace std;
 8 int main(){
 9     int n;
10     while(cin>>n&&n!=-1){
11         int s,t=0,dis=0;
12         while(n--){
13             int tt;
14             cin>>s>>tt;
15             dis+=s*(tt-t);
16             t=tt;
17         }
18         printf("%d miles\n",dis);
19     }
20     return 0;
21 } 
时间: 2024-11-04 12:36:09

poj 2017 Speed Limit的相关文章

[ACM] poj 2017 Speed Limit

Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17030   Accepted: 11950 Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have driven. Fortunately

POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)

Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17578   Accepted: 12361 Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have driven. Fortunately

zoj 2176 Speed Limit

Speed Limit Time Limit: 2 Seconds      Memory Limit: 65536 KB Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can rec

POJ2017 Speed Limit

水题,用一个变量存一下上一个时间即可. Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17698   Accepted: 12433 Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have

E - Speed Limit(2.1.1)

E - Speed Limit(2.1.1) Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have dr

poj 3619 Speed Reading

Speed Reading Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8431   Accepted: 3935 Description All K (1 ≤ K ≤ 1,000) of the cows are participating in Farmer John's annual reading contest. The competition consists of reading a single boo

POJ 3619 Speed Reading(简单题)

[题意简述]:有K头牛,N页书,每次第i头牛每分钟只能读Si页书,连续读Ti分钟,之后休息Ri分钟.现在问我们第i头牛花费多少时间可以读完这N页书. [分析]:简单的模拟 //220K 32Ms #include<iostream> #include<cmath> using namespace std; int main() { double N,K,Si,Ti,Ri; cin>>N>>K; double a = N; for(int i = 0;i<

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

题目链接: PKU:http://poj.org/problem?id=3653 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1934 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2722 Description The Gorelians are a warlike race that travel the universe conquering new world