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. eclipse创建maven的ssm项目

    自己接触ssm框架有一段时间了,从最早的接触新版ITOO项目的(SSM/H+Dobbu zk),再到自己近期来学习到的<淘淘商城>一个ssm框架的电商项目.用过,但是还真的没有自己搭建过, ...

  2. 数据结构(1) 第一天 算法时间复杂度、线性表介绍、动态数组搭建(仿Vector)、单向链表搭建、企业链表思路

    01 数据结构基本概念_大O表示法 无论n是多少都执行三个具体步骤 执行了12步 O(12)=>O(1) O(n) log 2 N = log c N / log c N (相当于两个对数进行了 ...

  3. C++进阶 STL(2) 第二天 一元/二元函数对象、一元/二元谓词、stack容器、queue容器、list容器(双向链表)、set容器、对组、map容器

    01 上次课程回顾 昨天讲了三个容器 string  string是对char*进行的封装 vector 单口容器 动态数组 deque(双端队列) 函数对象/谓词: 一元函数对象: for_each ...

  4. [SCOI2010] 股票交易 (单调队列优化dp)

    题目描述 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价为每股APi, ...

  5. https自签证书

    linux自带openssl,所以最好在linux平台操作 第一步:生成采用des3算法保护的私钥:openssl genrsa -des3 -out private-rsa.key 1024 命令执 ...

  6. Linux Shell脚本编程-语句控制

    过程式编程语言bash脚本编程面向过程的编程  顺序执行:默认法则,按照顺序一条一条语句执行  选择执行:分支,条件判断,符合条件的分支予以执行  循环执行:将同一段代码反复执行有限次,所以循环必须有 ...

  7. OOP 面向对象 七大原则 (一)

    OOP 面向对象   七大原则 (一) 大家众所周知,面向对象有三大特征继承封装多态的同时,还具有这七大原则,三大特征上一篇已经详细说明,这一篇就为大家详解一下七大原则: 单一职责原则,开闭原则,里氏 ...

  8. IAR for MSP430 关于添加自定义头文件的两种方法【转】

    前言:第一次接触这个软件,编译一个例程一直出现没有包含头文件的错误,在网上找了好几个方法都没什么效果,看到了篇文章,利用里面的方法1解决了,特此复制下来保存学习用. 原文链接:https://blog ...

  9. 【java项目实战】dom4j解析xml文件,连接Oracle数据库

    简单介绍 dom4j是由dom4j.org出品的一个开源XML解析包.这句话太官方.我们还是看一下官方给出的解释.例如以下图: dom4j是一个易于使用的.开源的,用于解析XML,XPath和XSLT ...

  10. fontend-githubs

    https://github.com/dypsilon/frontend-dev-bookmarks