zoj 2176 Speed Limit
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的更多相关文章
- Speed Limit 分类: POJ 2015-06-09 17:47 9人阅读 评论(0) 收藏
Speed Limit Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17967 Accepted: 12596 Des ...
- E - Speed Limit(2.1.1)
E - Speed Limit(2.1.1) Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I ...
- [ACM] poj 2017 Speed Limit
Speed Limit Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17030 Accepted: 11950 Des ...
- poj 2017 Speed Limit
Speed Limit Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17704 Accepted: 12435 Des ...
- POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)
Sp ...
- Kattis - Speed Limit
Speed Limit Bill and Ted are taking a road trip. But the odometer in their car is broken, so they do ...
- Poj 2017 Speed Limit(水题)
一.Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they ...
- ZOJ 2674 Strange Limit
欧拉函数. #include<iostream> #include<stdio.h> #include<string.h> #include<algorith ...
- Speed Limit
http://poj.org/problem?id=2017 #include<stdio.h> int main() { int n,mile,hour; ) { ,h = ; whil ...
随机推荐
- WPF CanExecuteChanged
继承ICommand ,RelayCommand命令 public class RelayCommand : ICommand { private readonly Action _execute; ...
- 基于Servlet+smartUpload的文件上传
文件上传在web应用中是非常常见的,现在我就介绍下基于servlet的文件上传,基于Struts2的文件上传可以看: 页面端代码: <%@ page language="java&qu ...
- 怎样将python的文件转化为windows的可执行程序
最近我在刚入手python,其中就学到了怎样将python的py格式文件转化为windows的exe执行程序, 是这样的,首先要创建一个py文件,这里给截图吧 接下来就以这个python文件为例创建一 ...
- Handler消息机制的一些原理(直接用code讲解)——Android开发
package com.example.handlertest; import android.os.Bundle; import android.os.Handler; import android ...
- github入门一
一.首先安装gitbash(自行百度)我使用的版本是Git-2.12.2.2-64-bit.exe 二.配置gitbash本地客户端 1.初始设置 1.1.设置姓名和邮箱地址 git config - ...
- 当ThreadLocal碰上线程池
ThreadLocal使用 ThreadLocal可以让线程拥有本地变量,在web环境中,为了方便代码解耦,我们通常用它来保存上下文信息,然后用一个util类提供访问入口,从controller层到s ...
- Clown without borders 2017/1/9
原文 Taking laughter to those who need it most "When will you all return again?"the Croatian ...
- The Django Book 第三章 试图和URL配置
之前自学Django也有一段时间了,再过一个月就要入职新公司了(Python Django开发),即使现在还在入门级徘徊,再好好把Django基础过一遍吧. The Django Book 第三章 试 ...
- 网络大牛如何回答Chrome的15个刁钻面试题?
(内容来自网络整理) Google的面试题在刁钻古怪方面相当出名,甚至已经有些被神化的味道.这里整理出15道Google面试题并一一给出了网络大牛的答案,其中不少都是流传很广的. 第1题:让你清洗西雅 ...
- 优先队列的使用——Expedition
一.题目描述 你需要驾驶一辆卡车行驶L单位距离.最开始时,卡车上有P单位的汽油.卡车每开1单位距离需要消耗1单位的汽油.如果在途中车上的汽油耗尽,卡车就无法继续前行,因而无法到达终点.中途共有N个加油 ...