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 ...
随机推荐
- WebService_Demo
简述 使用IDEA开发webservice服务,从零开始一步一步指引你. 服务端开发 首先创建一个webservice项目,如下图 创建完项目后idea会帮我们创建一个类,helloword,我们把它 ...
- .net 键盘
private void txtGoodsGroup_KeyPress(object sender, KeyPressEventArgs e) { base.OnKeyPress(e); if ((i ...
- js中函数的理解
在JavaScript中,函数是一个极容易引起误解或引发歧义的数据类型,它可以是独立的函数类型,又可以作为对象的方法,也可以被称为类或构造器,还可以作为函数对象而存在等.
- 洛谷 P1902 刺杀大使
刺杀大使 一道并不难的二分题,竟让我交了上20次,诶,果然还是我太弱了. 看完题目就基本想到要怎么做了: 只需要对最小伤害代价进行二分即可,check()函数里用搜索判断是否可以到达最后一行,这里的c ...
- Vue实例的4个常用选项
1.过滤器 filters:在不改变的data的情况下输出前端页面需要的格式数据.例如将小数过滤为整数等.filters是一个对象,里边定义一个function方法,function传入一个参数,fu ...
- 4G牌照影响
与3G牌照发放整整讨论了10年不同,4G牌照发放在2009年3G规模建设4年后就进行了发放,也颇匹配于行业的加速度.那么,4G到底会在哪些方面.在何种程度上改变中国呢?其实,4G的影响可能没有那么大, ...
- http协议参数详解
整理一下http协议中的一些参数详解 截取了一个当前项目中的请求作为示例: Genaral:通用头 Request URL:当前请求的请求地址 Request Method:请求类型 get.post ...
- 洛谷 P1276 校门外的树(增强版)
题目描述 校门外马路上本来从编号0到L,每一编号的位置都有1棵树.有砍树者每次从编号A到B处连续砍掉每1棵树,就连树苗也不放过(记 0 A B ,含A和B):幸运的是还有植树者每次从编号C到D 中凡是 ...
- Window10 开启传统启动界面
Windows 10沿袭了Windows 8的快速启动,导致在启动过程中无法通过按F8进入启动选项,这样当系统遇到问题无法进入时根本无法通过进入安全模式等方式进行处理(当然通过其他一些工具还是能够引导 ...
- 计算机图形学:贝塞尔曲线(Bezier Curve)
计算机图形学:贝塞尔曲线(Bezier Curve) 贝塞尔能由贝塞尔样条组合而成,也可产生更高维的贝塞尔曲面.