Kattis - Speed Limit
Speed Limit
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 22 hours at 2020 miles per hour, then 6−2=46−2=4 hours at 3030 miles per hour, then 7−6=17−6=1hour at 1010 miles per hour. The distance driven is then 2⋅20+4⋅30+1⋅10=40+120+10=1702⋅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 nn, 1≤n≤101≤n≤10, followed by nn pairs of values, one pair per line. The first value in a pair, ss, is the speed in miles per hour and the second value, tt, is the total elapsed time. Both ss and tt are integers, 1≤s≤901≤s≤90 and 1≤t≤121≤t≤12. The values for ttare always in strictly increasing order. A value of −1−1 for nn 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 1 | Sample Output 1 |
---|---|
3 |
题意
给出某一时刻的时速,求一共走了多少公里
思路
注意时间要减掉前面的时间才能计算当前时速行走的距离
代码
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
while(cin >> t && t != -) {
int a[], b[];
for(int i = ; i < t; i++) {
cin >> a[i] >> b[i];
}
int sum = ;
for(int i = ; i < t; i++) {
sum += a[i] * (b[i] - b[i - ]);
}
printf("%d miles\n", sum);
}
}
Kattis - 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 ...
- zoj 2176 Speed Limit
Speed Limit Time Limit: 2 Seconds Memory Limit: 65536 KB Bill and Ted are taking a road trip. B ...
- POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)
Sp ...
- Poj 2017 Speed Limit(水题)
一.Description Bill and Ted are taking a road trip. But the odometer in their car is broken, so they ...
- Speed Limit
http://poj.org/problem?id=2017 #include<stdio.h> int main() { int n,mile,hour; ) { ,h = ; whil ...
- PyTorch DataLoader NumberWorkers Deep Learning Speed Limit Increase
这意味着训练过程将按顺序在主流程中工作. 即:run.num_workers. ,此外, ,因此,主进程不需要从磁盘读取数据:相反,这些数据已经在内存中准备好了. 这个例子中,我们看到了20%的加 ...
随机推荐
- JS 马托货物
大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,该如何调配? <!DOCTYPE html> <html> <head> < ...
- shell分析nginx日志
以下脚本都是基于上面日志格式的,如果你的日志格式不同需要调整awk后面的参数. 分析日志中的UserAgent cat access_20130704.log | awk -F "\&quo ...
- vue学习笔记——脚手架安装
项目启动:npm run build 脚手架 vue cli vue cli --2 安装命令 #全局安装 npm install --global vue-cli #卸载vue-cli npm u ...
- js中浏览器兼容startsWith 、endsWith 函数
在做js开发的时候用到了startsWith函数时,发现各个浏览器不兼容问题,因为对开发来说,chrome浏览器最好用,就一直在chrome浏览器中使用这两个函数没有任何问题,但在ie浏览器访问就直接 ...
- ubuntu上的arm-elf-tools -20040427.sh 下载及安装问题的解决
要完成uclinux在ARM上的移植,必须有这个工具. 下载地址:http://opensrc.sec.samsung.com/download.html 这个网站上还有许多其它资源可以下载.我选择 ...
- 探索Python的多态是怎么实现的
多态是指通过基类的指针或者引用,在运行时动态调用实际绑定对象函数的行为. 对于其他如C++的语言,多态是通过在基类的函数前加上virtual关键字,在派生类中重写该函数,运行时将会根据对象的实际类型来 ...
- SpringMVC的DispatcherServlet加载过程
首先在web.xml中配置容器启动监听器,这样在容器启动后Spring会初始化一个ServletContext,负责加载springmvc的九大组件(调用DispatcherServlet.onRef ...
- 0111MySQL优化的奇技淫巧之STRAIGHT_JOIN
转自博客http://huoding.com/2013/06/04/261 问题 通过「SHOW FULL PROCESSLIST」语句很容易就能查到问题SQL,如下: SELECT post.* F ...
- oracle定时器执行一遍就不执行或本就不执行
转:http://blog.csdn.net/qq_23311211/article/details/76283689 以sqlplus/ assysdba进入sql命令模式,使用sql:select ...
- codeforces Towers 题解
Little Vasya has received a young builder's kit. The kit consists of several wooden bars, the length ...