[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 ...
随机推荐
- 你应该知道的Virtual Studio
最近,在网上看到一篇关于VS2008的一些提示,可以提高开发效率,我把它翻译过来,当然里面也有很多自己的想法,分享一下,大家可以择有用的提示而用之. 参考:每个开发者都应该知道的提示和诀窍 提示一:拷 ...
- 通过Windows PowerShell远程管理计算机(精简版)
现在你手中有一台server(主控端),你打算通过主控端远程管理多台server(被控端).这个过程可以通过Windows PowerShell来完成. 首先在被控端上以管理员权限打开PowerShe ...
- lambda续集——2
隐式捕获: 出了显式列出我们希望使用的来自函数的变量外,还可以让编译器根据lambda体中的代码来推断我们要使用哪些变量.为了指示编译器推断捕获列表,应在捕获列表中写一个&或=.&告诉 ...
- Activiti - 新一代的开源BPM引擎
Activiti 背景简介.服务和功能介绍 背景介绍 Activiti 其核心是 BPMN 2.0 的流程引擎.BPMN 是目前被各 BPM 厂商广泛接受的 BPM 标准,全称为 Business P ...
- 【WPF】CommandParameter解决多传参问题
方法一:传参按钮控件自身绑定的ItemSource 用WAF框架实现MVVM,按钮的点击事件都要通过Command来传递到这个View对应的ViewModel上,再通过ViewModel传递到上层的C ...
- [app]Linux的setitimer和sleep冲突
在Linux中使用setitimer和sleep会冲突,二者都是用信号 碰上一个头疼的问题,主程序在sleep的时候,总是被开的一个timer的signal callback所影响, 每当timer的 ...
- Win10如何显示系统托盘所有图标
最快就是小娜搜索通知 打开Win10“设置”,依次进入“系统 – 通知和操作”,设置界面如图: 点击“选择在任务栏上显示哪些图标”打开如图所示的界面:
- CentOS 6编译安装yum和配置常用的yum源
安装环境:VPS,CentOS 6 + devel包 一.安装相应的软件 1.安装python 下载Python源码包 [root@akinlau ~]# wget http://www.python ...
- Entity Framework表拆分
一.概念 表拆分:一个表拆分成多个实体,例如Photograph表,可以拆分为Photograph和PhotographFullImage两张表. Photograph实体结构: using Syst ...
- r指定位置插入一列
y<-1:4 data1 <-data.frame(x1=c(1,3,5,7), x2=c(2,4,6,8),x3=c(11,12,13,14),x4=c(15,16,17,18)) da ...