[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 ...
随机推荐
- JS面向对象教程
初探 我们知道Javascript中的变量定义基本如下: var name = 'Chen Hao';; var email = 'haoel(@)hotmail.com'; var website ...
- PhantomJS与CasperJS在Windows下的安装与使用
按照网上的教程来呢,一定是不好使的,这是常理. 所以必须要告诉你怎么使用Phantomjs…… 这么用! 1.下载Phantomjs的压缩包并解压缩: 2.在bin目录(包含phantomjs.exe ...
- Android开发:keytool' 不是内部或外部命令 也不是可运行的程序
今天在更改keystore密码的时候,发生了这个问题:keytool' 不是内部或外部命令 也不是可运行的程序. 本来以为很简单觉得的问题,在网上搜索了一大堆答案,都不是我想要的,故在此记录下我的解决 ...
- pygame绘制文本
def drawText(self,text,posx,posy,textHeight=48,fontColor=(0,0,0),backgroudColor=(255,255,255)): font ...
- centos修改ip mac等
CentOS修改mac http://www.haowlan.com/jishuluntan/488.html CentOS 修改IP地址, DNS, 网关 http://www.21andy.com ...
- tomcat架构分析(connector BIO 实现)
出处:http://gearever.iteye.com 在tomcat架构分析(概览)中已经介绍过,connector组件是service容器中的一部分.它主要是接收,解析http请求,然后调用本s ...
- cocos2dx遇到的坑2
记录下在cocos2dx 2.x时代遇到的问题 1.cocos2dx retain 在onenter时,在onexit时 release 2.先结束定时器再退出界面 3.在不同帧里数据是有可能不一 ...
- C语言 · 报时助手
基础练习 报时助手 时间限制:1.0s 内存限制:512.0MB 锦囊1 判断,字符串输出. 锦囊2 按要求输出,判断特殊情况. 问题描述 给定当前的时间,请用英文的读法 ...
- R语言实战实现基于用户的简单的推荐系统(数量较少)
R语言实战实现基于用户的简单的推荐系统(数量较少) a<-c(1,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,5,6,6,7,7) b<-c(1,2,3,4,2,3,4 ...
- eclipse lua
eclipse中的ldt插件是Lua Development Tools,开发lua专用的插件: 1.点击help->install new softWare,输入http://luaeclip ...