Speed Limit

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 per hour

Total elapsed time in hours

20

2

30

6

10

7

this means they drove 22 hours at 2020 miles per hour, then 6−2=46−2=4 hours at 3030 miles per hour, then 7−6=17−6=1hour at 1010 miles per hour. The distance driven is then 2⋅20+4⋅30+1⋅10=40+120+10=1702⋅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 nn, 1≤n≤101≤n≤10, followed by nn pairs of values, one pair per line. The first value in a pair, ss, is the speed in miles per hour and the second value, tt, is the total elapsed time. Both ss and tt are integers, 1≤s≤901≤s≤90 and 1≤t≤121≤t≤12. The values for ttare always in strictly increasing order. A value of −1−1 for nn 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 1 Sample Output 1
  1. 3
  2. 20 2
  3. 30 6
  4. 10 7
  5. 2
  6. 60 1
  7. 30 5
  8. 4
  9. 15 1
  10. 25 2
  11. 30 3
  12. 10 5
  13. -1

题意

给出某一时刻的时速,求一共走了多少公里

思路

注意时间要减掉前面的时间才能计算当前时速行走的距离

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int t;
  5. while(cin >> t && t != -) {
  6. int a[], b[];
  7. for(int i = ; i < t; i++) {
  8. cin >> a[i] >> b[i];
  9. }
  10. int sum = ;
  11. for(int i = ; i < t; i++) {
  12. sum += a[i] * (b[i] - b[i - ]);
  13. }
  14. printf("%d miles\n", sum);
  15. }
  16. }

Kattis - Speed Limit的更多相关文章

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

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

  2. E - Speed Limit(2.1.1)

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

  3. [ACM] poj 2017 Speed Limit

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

  4. poj 2017 Speed Limit

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

  5. zoj 2176 Speed Limit

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

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

                                                                                                      Sp ...

  7. Poj 2017 Speed Limit(水题)

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

  8. Speed Limit

    http://poj.org/problem?id=2017 #include<stdio.h> int main() { int n,mile,hour; ) { ,h = ; whil ...

  9. PyTorch DataLoader NumberWorkers Deep Learning Speed Limit Increase

    这意味着训练过程将按顺序在主流程中工作. 即:run.num_workers.   ,此外, ,因此,主进程不需要从磁盘读取数据:相反,这些数据已经在内存中准备好了. 这个例子中,我们看到了20%的加 ...

随机推荐

  1. spring cloud(二) zuul

    spring cloud 网关 zuul 搭建过程 1. 新建boot工程 pom引入依赖 <dependency> <groupId>org.springframework. ...

  2. 【模板】最大流模板(dinic)

    题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行 ...

  3. 《代码敲不队》第八次团队作业:Alpha冲刺 第一天

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 代码敲不队 作业学习目标 掌握软件编码实现的工程要求. 第一天 日期:2019/6/15 团队项目 ...

  4. @Autowired 作用范围

    一.@AutoWired 可以作用于:构造器.方法.参数.属性 二.作用在方法上 @Component public class Student{ private Book book; public ...

  5. jQuery选择器练习中,带空格和不带空格的问题

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. BP网络中的反向传播

    本文的主要参考:How the backpropagation algorithm works 下面是BP网络的参数结构示意图 首先定义第l层网络第j个神经元的输出(activation) 为了表示简 ...

  7. [Preference] How to avoid Forced Synchronous Layout or FSL to improve site preference

    When tigger site updates the layout, it always follow this order: Javascript trigger style changes, ...

  8. SpringMVC 理论与有用技术(二)文件上传

    文件上传相信大家都做过,差点儿全部的项目都有上传文件的功能,尤其是BS架构的项目中经常被列为常规功能来开发.不管是在开发.NET 项目还是java项目我们会用到非常多的框架,这个功能也被集成到了框架之 ...

  9. POJ-3984-迷宫问题-BFS(广搜)-手写队列

    题目链接:id=3984">http://poj.org/problem? id=3984 这个本来是个模板题,可是老师要去不能用STL里的queue,得自己手写解决.ORZ....看 ...

  10. ClassNotFoundException和NoClassDefFoundError的差别

    正如它们的名字所说明的:NoClassDefFoundError是一个错误(Error),而ClassNOtFoundException是一个异常,在Java中错误和异常是有差别的,我们能够从异常中恢 ...