Speed Limit - POJ 2017 水题
来源:互联网 发布:b站弹幕源码 编辑:程序博客网 时间:2024/05/18 02:14
Speed Limit
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 17023 Accepted: 11945
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
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.
For example, if their log shows
Speed in miles perhourTotal elapsed time in hours202306107
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
320 230 610 7260 130 5415 125 230 310 5-1
Sample Output
170 miles180 miles90 miles
题意:一个人以多少的速度开到几个小时,问一共行驶的路程。
思路:大水,无需解释。
AC代码如下:
#include<cstdio>#include<cstring>using namespace std;int main(){ int n,i,j,k,sum,t,speed; while(~scanf("%d",&n) && n!=-1) { sum=0; k=0; for(i=1;i<=n;i++) { scanf("%d%d",&speed,&t); sum+=speed*(t-k); k=t; } printf("%d miles\n",sum); }}
0 0
- Poj 2017 Speed Limit(水题)
- Speed Limit - POJ 2017 水题
- POJ 2017 Speed Limit
- POJ 2017 Speed Limit
- poj 2017 Speed Limit
- POJ 2017 Speed Limit
- poj 2017 Speed Limit
- POJ 2017 - Speed Limit
- POJ 2017 Speed Limit
- POJ 2017 Speed Limit
- [POJ] 2017 -> Speed Limit
- poj 2017 Speed Limit
- Speed Limit POJ 2017
- POJ 2017:Speed Limit
- 【2017】Speed Limit (水题)POJ
- [ACM] poj 2017 Speed Limit
- poj 2017 Speed Limit -- 模拟
- POJ 2017 Speed Limit G++
- error LNK2001: unresolved external symbol GUID_SELF_DEFINE
- 10. 泛型 Part 3 --- 学习笔记
- android中Activity的启动方式
- skipped by case
- 关于各类存储器的一些简单的认识
- Speed Limit - POJ 2017 水题
- jQuery中实现:当文本框输入值,验证值不符合规格,然后是文本框输出原来的值的方法
- 四象限法则
- VNC方式连接树莓派
- 约束规划建模技巧总结---中间变量和全局约束
- jsp中引入脚本文件的路径问题
- view setAnimation 中的动画何时会被调用
- 多进程及多线程之间同步与通信
- Parencodings - POJ 1068 水题