Speed Limit


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 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".

Example input: Example output:
3
20 2
30 6
10 7
2
60 1
30 5
4
15 1
25 2
30 3
10 5
-1
170 miles
180 miles
90 miles

 #include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;
int sum, pre, cur, s;
while(cin >> n){
if(n == -)
break;
cin >> s >> pre;
sum = s * pre;
for(int i = ; i < n; i++){
cin >> s >> cur;
sum += s * (cur - pre);
pre = cur;
}
cout << sum << " miles" << endl;
}
return ;
}

zoj 2176 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. POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)

                                                                                                      Sp ...

  6. Kattis - Speed Limit

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

  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. ZOJ 2674 Strange Limit

    欧拉函数. #include<iostream> #include<stdio.h> #include<string.h> #include<algorith ...

  9. Speed Limit

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

随机推荐

  1. javaScript面向对像

    1.创建对象 <script type="text/javascript"> function Flower(name,addre) { this.name=name; ...

  2. Spring mvc简单案例

    jar包 <!--junit--><dependency> <groupId>junit</groupId> <artifactId>jun ...

  3. 安装ubuntu虚拟环境

    一. 安装 1. 准备: 1). Oracle VM VirtualBox https://www.virtualbox.org/ 2). Ubuntu 18.04.2 LTS https://ubu ...

  4. github入门之基本操作--4

    1.初始化仓库 如果成功执行git init 命令,该目录下会生成一个.git的目录 2.查看仓库状态 *注: 实际工作中,git status使用次数非常多,一定要记住.因为当工作树和仓库被操作的过 ...

  5. SQL 转换函数

    1.字符串与字符串相加 字符串相加   得到的是拼接成一列的字符串类型 例如 select name+code from car       name是nvarchar  code也是nvarchar ...

  6. 怎样配置JDK开发环境

    (1)我们需要配置三个环境变量,分别是JAVA_HOME,CLASSPATH,Path (2)变量名输入:JAVA_HOME,变量值输入:D:\Java\jdk1.8.0_05点击确定. 需要特别注意 ...

  7. JavaScript(appendChild添加节点)

    首先,我们有一个编辑器,有一个简单的HTML页面,页面的级别分别 --> html  -->head[title,meta,script,link] -- body,然后再新建一个inde ...

  8. python打飞机pro版

    # -*- coding: utf-8 -*- import pygame from sys import exit import random pygame.init() screen = pyga ...

  9. js 上传图片

    <div class="block-input" style="height: 90px"> <span><i class=&qu ...

  10. OpenWrite方法打开现有文件并进行写入

    实现效果: 知识运用: File类的OpenWrite方法 //实现打开现有文件以进行写入 public static FileStream OpenWrite (string path) Encod ...