E - Speed Limit(2.1.1)

时间:2022-09-13 15:32:41
E - Speed Limit(2.1.1)

Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

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
#include<iostream>
using namespace std;
int main( )
{
int n;
int a,b,s,k;
while(cin>>n&&n>0)
{
s=0,k=0;
while(n--)
{
cin>>a>>b;
s=s+a*(b-k);
k=b; }
cout<<s<<" miles"<<endl;
}
return 0;
}


E - Speed Limit(2.1.1)的更多相关文章

  1. Speed Limit 分类: POJ 2015-06-09 17&colon;47 9人阅读 评论&lpar;0&rpar; 收藏

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

  2. &lbrack;ACM&rsqb; poj 2017 Speed Limit

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

  3. poj 2017 Speed Limit

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

  4. zoj 2176 Speed Limit

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

  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&lpar;水题&rpar;

    一.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. HDU 3030 - Increasing Speed Limits

    Problem Description You were driving along a highway when you got caught by the road police for spee ...

随机推荐

  1. Cookie和Session的总结

    1.开篇 在之前学习这一段的时候我一直有点没弄清楚,其实对Session这块的理解还可以,但是Cookie感觉始终还是欠缺点火候.之后的很长一段时间都基本上很少用Cookie了,渐渐的也淡忘了这一块的 ...

  2. hibernate的缓存机制

    hibernate提供两种缓存:一级缓存和二级缓存 一.一级缓存:也就是Session缓存(又称作事务缓存):Hibernate内置的,不能卸除. 在同一个Session里面,第一次调用get()方法 ...

  3. &lbrack;LintCode&rsqb; Happy Number 快乐数

    Write an algorithm to determine if a number is happy. A happy number is a number defined by the foll ...

  4. IO笔记

    Java流操作有关的类或接口: Java流类图结构: 1.文件操作时,注意要使用File.separator来代替/分隔符实现跨平台 2.RandomAccessFile类并不是流体系中的一员,但常用 ...

  5. 【转】Xcode7&period;1环境下上架iOS App到AppStore 流程 &lpar;Part 二&rpar;

    原文网址:http://www.cnblogs.com/ChinaKingKong/p/4964549.html 前言部分 part二部分主要讲解 iOS App IDs 的创建.概要文件的配置.以及 ...

  6. 【HDOJ】1811 Rank of Tetris

    并查集+拓扑排序.使用并查集解决a = b的情况. #include <iostream> #include <cstdio> #include <cstring> ...

  7. 单例模式在Unity中的应用

    起因:每个游戏场景中都会有许多的游戏对象,而各个游戏场景之间也是同等的关系.如何去管理它们,是我们要解决的问题. 场景中各脚本间的直接访问,会在各脚本间形成一个巨大而又混乱的网络,这给以后代码的维护带 ...

  8. Python并发编程的几篇文章

    Python几种并发实现方案的性能比较 http://www.elias.cn/Python/PyConcurrency?from=Develop.PyConcurrency python并发编程 h ...

  9. sharding-jdbc之——分库分表实例

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/79368021 一.概述 之前,我们介绍了利用Mycat进行分库分表操作,Mycat ...

  10. 【WP8】ResourceDictionary

    WP8中引用资源字典 当我们定义的样式太多的时候,我们可以把样式分别定义在不同的文件中,然后通过 MergedDictionaries 应用到其他资源字典中,看下面Demo 我们可以把样式定义在多个文 ...