Poj 2017 Speed Limit(水题)
一、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
二、题解
太难得题做得头痛,太容易的题呢又做得没意思,哎!
三、java代码
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,i,j,a[],b[],sum;
while((n=sc.nextInt())!=-1){
a=new int[n];
b=new int[n];
sum=0;
for(i=0;i<n;i++){
a[i]=sc.nextInt();
b[i]=sc.nextInt();
}
sum=a[0]*b[0];
i=0;
j=i+1;
while(j<n){
sum+=(b[j]-b[i]) * a[j];
i++;
j++;
}
System.out.println(sum+" miles");
}
}
}
Poj 2017 Speed Limit(水题)的更多相关文章
- POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)
Sp ...
- [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 ...
- POJ 1488 Tex Quotes --- 水题
POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- poj 2105 IP Address(水题)
一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...
随机推荐
- php自定义函数: amr转mp3格式
<?php function amr2mp3($file){ if (file_exists($file . '.mp3') == true) { return; } else { $param ...
- opengl绘制图片
#include <GL/glew.h>#include <glut.h>#include "FreeImage.h"#include <stdio. ...
- [Tjoi2018]数学计算
[Tjoi2018]数学计算 BZOJ luogu 线段树分治 是不是想问为什么不暴力做? 模数没说是质数,所以不一定有逆元. 然后就是要每次build一下把线段树权值init成1, 博猪不知道为什么 ...
- 我的Java开发学习之旅------>Java 格式化类(java.util.Formatter)基本用法
本文参考: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html http://www.blogjava.net/ ...
- The given 'driver' ] is unknown, Doctrine currently supports only the follo wing drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo
[Doctrine\DBAL\DBALException] The given 'driver' ] ...
- 两个Java项目之间相互调用
转自:http://dysfzhoulong.iteye.com/blog/1008747 一个项目A另一个项目B:(项目A和项目B都是Java写的项目) 在A项目中怎么调用B项目中的类和方法 有两种 ...
- setTimeout解决循环值的几种方法
for(var i=0;i<5;i++){ setTimeout(function(){ console.log(`错误 ${i}`); },0) } for(var i=0;i<5;i+ ...
- linux awk数组相关操作介绍
用awk进行文本处理,少不了就是它的数组处理.那么awk数组有那些特点,一般常见运算又会怎么样呢.我们先看下以下的一些介绍,结合样例我们会解说下它的不同之处.在 awk 中数组叫做关联数组(assoc ...
- model特性
1.scope http://blog.csdn.net/lissdy/article/details/51107883 2.ActiveConcern http://www.tuicool.com/ ...
- jQuery设计理念
jQuery设计理念 引用百科的介绍: jQuery是继prototype之后又一个优秀的Javascript框架.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1. ...