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, 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

 
    题目分析:输入n行,每行是速度和运行总时间。  也就是说:以样例为例:运行到2小时末的时候都是20的速度,运行到6小时末的时候期间的都是30的速度,==中间4小时是30的速度
    运行到7小时末的时候是10的速度,也就是说(7-6)的1小时是10的速度,输出总的行驶距离。
    代码:

//直叙式的简单模拟题
#include <stdio.h>
#include <string.h> int main()
{
int n;
int i, j;
int a[20], b[20]; while(scanf("%d", &n)&&n!=-1)
{
for(i=0; i<n; i++)
{
scanf("%d %d", &a[i], &b[i] );
}
int ans=0, t=0; for(j=0; j<n; j++)
{
ans=ans+a[j]*(b[j]-t);
t=b[j];
}
printf("%d miles\n", ans );
}
return 0;
}

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

  1. [ACM] poj 2017 Speed Limit

    Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17030   Accepted: 11950 Des ...

  2. poj 2017 Speed Limit

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

  3. Poj 2017 Speed Limit(水题)

    一.Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they ...

  4. Speed Limit 分类: POJ 2015-06-09 17:47 9人阅读 评论(0) 收藏

    Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17967   Accepted: 12596 Des ...

  5. E - Speed Limit(2.1.1)

    E - Speed Limit(2.1.1) Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I ...

  6. 利用链式队列(带头节点)解决银行业务队列简单模拟问题(c++)-- 数据结构

    题目: 7-1 银行业务队列简单模拟 (30 分)   设某银行有A.B两个业务窗口,且处理业务的速度不一样,其中A窗口处理速度是B窗口的2倍 —— 即当A窗口每处理完2个顾客时,B窗口处理完1个顾客 ...

  7. zoj 2176 Speed Limit

    Speed Limit Time Limit: 2 Seconds      Memory Limit: 65536 KB Bill and Ted are taking a road trip. B ...

  8. Kattis - Speed Limit

    Speed Limit Bill and Ted are taking a road trip. But the odometer in their car is broken, so they do ...

  9. POJ 2993 Emag eht htiw Em Pleh【模拟画棋盘】

    链接: http://poj.org/problem?id=2993 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

随机推荐

  1. centos7如何查看ip信息(centos 6.5以前都可以用ifconfig 但是centos 7里面没有了,centos 7用什么查看?)

    展开全部 centos7如何查看ip信息可以这样解决: 1.首先要先查看一下虚拟机的ip地址,因为ipconfig不是centos7,因此要使用 ip addr来查看. 2.查看之后你就会发现ens3 ...

  2. hdu 4961 数论 o(nlogn)

    Boring Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tot ...

  3. 小程序-地图API

    摘要 地图组件-map 注意事项&&Bug: 1.map 组件是由客服端创建的原生组件,它的层级是最高的. 2.请勿在scroll-view中使用map组件 3.css动画对map组件 ...

  4. Codeforces Round #511 (Div. 2) C. Enlarge GCD

    题目链接 题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点. 我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值, 如果直接赋值,会直接在exe内产生内存,否 ...

  5. 一个球,初始高度100,每次落下回弹一半高度,求第n次落下球走的距离

    def get_height(n): if n==1: eturn 150 return 100+sum([200*pow(0.5,i) for i in range(1,n)])+100*pow(0 ...

  6. BUPT复试专题—众数(2014)

    题目描述 有一个长度为N的非降数列,求数列中出现最多的数,若答案不唯一输出最小的数 输入 第一行T表示测试数据的组数(T<100) 对于每组测试数据: 第一行是一个正整数N表示数列长度 第二行有 ...

  7. iphone 消息推送 实现

    IPhone 消息推送实现 参考 资料 http://blog.csdn.net/victormokai/article/details/39501277 对生成pem 的补充 拿到mac 上生成导出 ...

  8. 手写 redux 和 react-redux

    1.手写 redux redux.js /** * 手写 redux */ export function createStore(reducer) { // 当前状态 let currentStat ...

  9. indexOf 和 lastIndexOf 的区别

    indexOf 和 lastIndexOf 是什么? indexOf 和 lastIndexOf 都是索引文件 indexOf 是查某个指定的字符串在字符串首次出现的位置(索引值) (也就是从前往后查 ...

  10. js跳出循环的方法区别( break, continue, return ) 及 $.each 的(return true 和 return false)

    js编程语法之break语句: break语句会使运行的程序立刻退出包含在最内层的循环或者退出一个switch语句. 由于它是用来退出循环或者switch语句,所以只有当它出现在这些语句时,这种形式的 ...