Speed Limit
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 17578   Accepted: 12361

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

Source

 
    题目分析:输入n行,每行是速度和运行总时间。  也就是说:以样例为例:运行到2小时末的时候都是20的速度,运行到6小时末的时候期间的都是30的速度,==中间4小时是30的速度
    运行到7小时末的时候是10的速度,也就是说(7-6)的1小时是10的速度,输出总的行驶距离。
    代码:

//直叙式的简单模拟题
#include <stdio.h>
#include <string.h> int main()
{
int n;
int i, j;
int a[20], b[20]; while(scanf("%d", &n)&&n!=-1)
{
for(i=0; i<n; i++)
{
scanf("%d %d", &a[i], &b[i] );
}
int ans=0, t=0; for(j=0; j<n; j++)
{
ans=ans+a[j]*(b[j]-t);
t=b[j];
}
printf("%d miles\n", ans );
}
return 0;
}

POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)的更多相关文章

  1. [ACM] poj 2017 Speed Limit

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

  2. poj 2017 Speed Limit

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

  3. Poj 2017 Speed Limit(水题)

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

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

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

  5. E - Speed Limit(2.1.1)

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

  6. 利用链式队列(带头节点)解决银行业务队列简单模拟问题(c++)-- 数据结构

    题目: 7-1 银行业务队列简单模拟 (30 分)   设某银行有A.B两个业务窗口,且处理业务的速度不一样,其中A窗口处理速度是B窗口的2倍 —— 即当A窗口每处理完2个顾客时,B窗口处理完1个顾客 ...

  7. zoj 2176 Speed Limit

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

  8. Kattis - Speed Limit

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

  9. POJ 2993 Emag eht htiw Em Pleh【模拟画棋盘】

    链接: http://poj.org/problem?id=2993 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

随机推荐

  1. miller_rabin + pollard_rho模版

    #include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> #incl ...

  2. Controller配置汇总

    1.通过Url对应Bean <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping ...

  3. TCP/IP 协议栈

    TCP(传输控制协议) 传输控制协议(Transmission Control Protocol,TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议,由IETF的RFC 793定义. 在因特 ...

  4. noip2013华容道

    题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...

  5. delphi函数大全

    delphi函数大全Abort                 函数    引起放弃的意外处理Abs                   函数    绝对值函数AddExitProc          ...

  6. Java主线程等待所有子线程执行完毕再执行解决办法(转)

    方法一: Thread.join()方法,亲测可行,thread.join()方法 Vector<Thread> ts = new Vector<Thread>(); for  ...

  7. poj 2135 Farm Tour 最小费最大流

    inf开太小错了好久--下次还是要用0x7fffffff #include<stdio.h> #include<string.h> #include<vector> ...

  8. 在Nginx上部署ThinkPHP,解决Pathinfo问题

    在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...

  9. mysql 安装与启动

    1.下载mysql installer 2.安装 一直点next,直到finish. 3.安装时的配置 安装完后,选择立即开始配置. 选择standard configuration 勾选安装mysq ...

  10. weex 项目 创建 远程 icon

    一.创建 远程 icon 步骤一:打开  阿里巴巴矢量图标库 官网:http://www.iconfont.cn/ 步骤二:选择项目需要的 icon 步骤三:添加到项目(没有项目会自动创建) 步骤四: ...