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%的加 ...
随机推荐
- vue自己写了一个div菜单,点击按钮展开,点击其他地方关闭这个div菜单
需求是通过点击body页面,在其他地方就关闭这个<div>菜单,给这个div一个id:problemList,但是点击我打开的按钮,不关闭. created () { document.o ...
- IOS与h5交互记录
博主之前做过移动端app嵌入网页,与Android和IOS有交互,一直没有时间分享过程.这里不多说Android交互啦-很简单,详细了解IOS与h5的交互吧. IOS不同语法和h5的交互所建立的JSB ...
- javascript 富文本 注意事项
富文本编辑器 div内嵌iframe iframe body contenteditable属性 true 整个iframe 即为可编辑框,创建时注意事项: 1.编辑 焦点问题 弹出新控件时为控件设置 ...
- 训练1-L
n个人一起排队接水,第i个人需要ai的时间来接水. 1 <= n <= 1000 1 <= a,i<= 1000 同时只能有一个人接水,正在接水的人和没有接水的人都需要等待. ...
- MAVN(自动创建maven项目骨架) 项目架构的生成
1.Maven的项目架构生成 A.打开DOS命令窗口选定文件的更跟目录 B:输入命令 mvn archetype:generate C:根据提示输入对应的标识 如图: 最后提示 SUCCESS 即为 ...
- vue项目优化--使用CDN和Gzip
使用vue-cli构建的vue项目,在打包发布的时候,发现打包后的文件体积很大,使用webpack-bundle-analyzer分析后,发现占用空间最多的是引用的第三方依赖.第三方的依赖文件可以使用 ...
- 【POJ】3122 Pie [二分查找]
题目地址:http://poj.org/problem?id=3122 二分每块饼的体积.为了保证精度,可以先二分半径的平方r*r,最后再乘以PI.要注意一点,要分的人数要包括自己,及f+1. #in ...
- jQuery练习总结(一)
第一个jQuery程序: 注意:使用jQuery时候定义单击事件使用的方法是click(function(){处理单击事件产生时所要执行的代码}) , 而JavaScript定义的单击事件则是 xx. ...
- Appium遇到问题:
问题一:问题org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possibl ...
- C/C++ 在处理文件所在路径下创建子目录
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50789265 在一些图像处理或者数据处 ...