[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 ...
随机推荐
- FileZilla server windows 2003系统下适用的版本
最新版的FileZilla server 在windows 2003系统下已经不能用了 http://files.cnblogs.com/files/airoot/FileZilla_Server-0 ...
- html5和css3学习历程
1.video,audio视频和音频的应用 <!doctype html><html> <head></head> <body> < ...
- ucos-III前言
年 uC/OS-III实时操作系统面世以来,uC/OS-III的性能和稳定性已经日趋完善.uC/OS-III对前面版本取精弃粕,推陈出新,功能和性能比起 uC/OS-II已经上了很大一步台阶.uC/O ...
- tipask 不能正常解析
<? if(!defined('IN_TIPASK')) exit('Access Denied'); include template('header'); ?> 代码如上,经查询为ph ...
- 【WPF/WAF】界面布局(View)文件的多层嵌套(Nest)
碎碎念:使用的是略冷门的Window Application Foundation(WAF)框架,搜到的都是WPF的UserControl用户控件的用法,实在蛋疼. 需求:主界面ShellWindow ...
- [小技巧]Linux的一些信息获取
1. Linux 系统登录之后,显示如下 Last login: Thu Jan :: UTC on ttyS0 Linux xxx # PREEMPT Wed Jul :: CST armv7l 那 ...
- java多线程有几种实现方法?线程之间如何同步
java中多线程的实现方法有两种:1.直接继承thread类:2.实现runnable接口: 同步的实现方法有五种:1.同步方法:2.同步代码块:3.使用特殊域变量(volatile)实现线程同步:4 ...
- Hibernate- QBC离线查询
package com.gordon.test; import java.util.List; import org.hibernate.Criteria; import org.hibernate. ...
- Java-jdbc连接简化类jdbcUtil
在src文件夹下创建配置文件 db.properties db.properties drivername=com.mysql.jdbc.Driver url=jdbc:mysql://localho ...
- 上手并过渡到PHP7(4)——取代fatal error的engine exceptions
上手并过渡到PHP7 取代fatal error的engine exceptions 泊学原文链接泊学代码秀视频 自从PHP 4以来,PHP的错误处理几乎就是一成不变的.只不过在PHP 5.0里添加了 ...