[ACM] poj 2017 Speed Limit
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 17030 | Accepted: 11950 |
Description
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 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
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
解题思路:
一段时间的速度*这一段时间=这一段时间走得距离,几段时间距离和累加就能够了。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <iomanip>
#include <cmath>
using namespace std; int n;
int s[12],t[12]; int main()
{
while(cin>>n&&n!=-1)
{
t[0]=0;
for(int i=1;i<=n;i++)
cin>>s[i]>>t[i];
int total=0;
for(int i=1;i<=n;i++)
total+=(t[i]-t[i-1])*s[i];
cout<<total<<" miles"<<endl;
}
return 0;
}
[ACM] poj 2017 Speed Limit的更多相关文章
- poj 2017 Speed Limit
Speed Limit Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17704 Accepted: 12435 Des ...
- 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 分类: 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 ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- zoj 2176 Speed Limit
Speed Limit Time Limit: 2 Seconds Memory Limit: 65536 KB Bill and Ted are taking a road trip. B ...
- Kattis - Speed Limit
Speed Limit Bill and Ted are taking a road trip. But the odometer in their car is broken, so they do ...
随机推荐
- nyoj592 spiral grid
spiral grid 时间限制:2000 ms | 内存限制:65535 KB 难度:4 描述 Xiaod has recently discovered the grid named &q ...
- ny325 zb的生日,ny456邮票分你一半
zb的生日 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 今天是阴历七月初五,acm队员zb的生日.zb正在和C小加.never在武汉集训.他想给这两位兄弟买点什么庆祝 ...
- eclipse ant 的自动部署(autobulid)
在写项目中,经常需要在 ctrl+s的时候自动编译并且把这个改动的文件copy至某个目录,除了eclipse自带 java脚本的web自动部署到项目中配置的目录下,但是不能随心所欲copy,比如其他文 ...
- hdu1495(经典bfs,平分水问题)
思路:搜索题,第一次做这种类型的题目吧,一开始表示不怎么明白题意所说的东东.其实就是要你判断可乐能不能被平分........ 有六种状态,从a瓶到b瓶,a-->c b-->a b- ...
- 【SpringMVC笔记】第四课 注解的处理器映射器和处理器适配器使用
一.注意点: 版本问题 spring3.2以前的版本,注解的映射器和适配器使用以下两个类. org.springframework.web.servlet.mvc.annotation.Default ...
- cocos2dx3.2利用ProgressTimer组合成评分控件
一.制作背景 如今非常多游戏或者应用须要评分,就是一般来说满分10分,一般用星星来表示. 那么cocos2dx里面怎样制作评分这种控件呢? 我的打算是进度条组合成即可了. 二.材料准备 如上图所看到的 ...
- /etc/fstab下的挂载类型defaults默认参数
[root@ob2 data]# cat /etc/fstab -98c0-59dbbcf8b040 / ext4 defaults UUID=e4ab7a0c-500f--bcd2-a77be0ce ...
- 用户数据验证的正确姿势之assert
用户数据验证灰常重要, 不用多说了, 但是实现方法(准确的说是表现形式)有很多人, 如何优雅的完成一个后端验证过滤器是一个值得考量的问题, 我尝试过许多方法, 比如validator.js模块, ex ...
- 数据导入报错 Got a packet bigger than‘max_allowed_packet’bytes
数据导入报错:Got a packet bigger than‘max_allowed_packet’bytes的问题 2个解决方法: 1.临时修改:mysql>set global max_a ...
- .NET操作Excel笔记
如果你新建一个项目的话,首先要添加Microsoft.Office.Core 与Microsoft.Office.Interop.Exce这两个应用,然后就能很方便的操作了,示例代码(只实现了简单的读 ...