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
3
20 2
30 6
10 7
2
60 1
30 5
4
15 1
25 2
30 3
10 5
-1

题意

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

思路

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

代码

#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
while(cin >> t && t != -) {
int a[], b[];
for(int i = ; i < t; i++) {
cin >> a[i] >> b[i];
}
int sum = ;
for(int i = ; i < t; i++) {
sum += a[i] * (b[i] - b[i - ]);
}
printf("%d miles\n", sum);
}
}

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. VS2008中C++打开Excel(MFC)

    VS2008中C++打开Excel(MFC)——摘自网络,并加以细化 第一步:建立project(新建项目) 英文版 中文版 选择C++下的MFC Application(基于对话框的项目) 英文版 ...

  2. day27-1 numpy模块

    目录 numpy array 一维数组 二维数组(用的最多) np.array和list的区别 获取多维数组的行和列 多维数组的索引 高级功能 多维数组的元素替换 多维数组的合并 通过函数方法创建多维 ...

  3. maven中tomcat7:run无法启动maven项目

    这几天在学习ssm相关整合,在使用maven时,发现了一些问题,就是明明按代码都差不多就是没法运行 这个是maven主项目的pom.xml的配置,我解决的方法是添加 <maven.compile ...

  4. Python基础学习_01修改代码所属作者

    1.修改开头的作者Author 2.具体步骤如下图 (1)点击下图所画的按钮 (2)具体操作如图所示,就可以得到自己想要的结果了.

  5. BZOJ 3774 最优选择 (最小割+二分图)

    题面传送门 题目大意:给你一个网格图,每个格子都有$a_{ij}$的代价和$b_{ij}$的回报,对于格子$ij$,想获得$b_{ij}$的回报,要么付出$a_{ij}$的代价,要么$ij$周围四联通 ...

  6. iptables防火墙和selinux

    iptables 存在以下两种方式: 一.service方式 查看防火墙状态: [root@centos6 ~]# service iptables status iptables:未运行防火墙 开启 ...

  7. 01.Python基础-3.集合容器

    1 列表list 1.1 列表介绍 Python内置的一种数据类型是列表:list. 有序的集合,可随时添加和删除其中的元素. 每个元素都分配一个数字 --它的位置,或索引.0,1,2,3-- 可存放 ...

  8. java深入的单例模式

    在GoF的23种设计模式中,单例模式是比较简单的一种.然而,有时候越是简单的东西越容易出现问题.下面就单例设计模式详细的探讨一下.   所谓单例模式,简单来说,就是在整个应用中保证只有一个类的实例存在 ...

  9. Spring 注解学习笔记

    声明Bean的注解: @Component : 组件,没有明确的角色 @Service : 在业务逻辑层(service层)使用 @Repository : 在数据访问层(dao层)使用. @Cont ...

  10. [SQL]选取随机行

    在sql server中语句如下: select     top 10     * from recordTable order by NEWID();