一、Description

Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time they
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 input consists of one or more data sets. Each set starts with a line containing an integer n, 1 <= n <= 10, followed by n pairs of values, one pair per line. The first value in a pair, s, is the speed in miles per hour and
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

For each input set, print the distance driven, followed by a space, followed by the word "miles"

二、题解

        太难得题做得头痛,太容易的题呢又做得没意思,哎!

三、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(水题)的更多相关文章

  1. POJ 2017 Speed Limit (直叙式的简单模拟 编程题目 动态属性很少,难度小)

                                                                                                      Sp ...

  2. [ACM] poj 2017 Speed Limit

    Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17030   Accepted: 11950 Des ...

  3. poj 2017 Speed Limit

    Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17704   Accepted: 12435 Des ...

  4. POJ 1488 Tex Quotes --- 水题

    POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...

  5. poj 1006:Biorhythms(水题,经典题,中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Des ...

  6. poj 1002:487-3279(水题,提高题 / hash)

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 236746   Accepted: 41288 Descr ...

  7. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...

  8. POJ 3641 Oulipo KMP 水题

    http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...

  9. poj 2105 IP Address(水题)

    一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...

随机推荐

  1. OLTP和OLAP

    1 OLTP和OLAP online transaction processing,联机事务处理.业务类系统主要供基层人员使用,进行一线业务操作,通常被称为联机事务处理. online analyti ...

  2. [luogu3359]改造异或树

    [luogu3359]改造异或树 luogu 和之前某道题类似只有删边的话考虑倒着加边 但是怎么统计答案呢? 我们考虑以任意点为根dfs一遍求出每个点到根的路径异或和s[i] 这样任意两点x,y的路径 ...

  3. sublime 快捷键,左菜单乱码

    sublime 快捷键安装 packagecontrol https://packagecontrol.io/installation#st3 import urllib.request,os,has ...

  4. 简易bootloader重定位问题

           单板选择NandFlash启动,则硬件上电后,系统会自己主动将NandFlash中的前4K内容复制到STEPSTONE即4K SRAM中.然后从SRAM中的0X0地址启动. 基于mini ...

  5. spring mvc 中Uploadify插件的使用

    具体过程不写了,直接上代码 jsp代码 $("#uplodefile").uploadify({ 'swf': '/statics/uploadify/uploadify.swf' ...

  6. 【三】MongoDB文档的CURD操作

    一.插入文档 使用insert方法插入文档到一个集合中,如果集合不存在创建集合,有以下几种方法: db.collection.insertOne({}):(v3.2 new)  #插入一个文档到集合中 ...

  7. 【Flask】下载多个文件

    使用zipfile模块可以将多个文件打包成zip文件进行下载,但是常规的操作方式会在服务器磁盘上生成一个zip文件占用磁盘空间. 后引入BytesIO将文件写入到内存中然后下载: def dl_pla ...

  8. while & do-while

    while的形式——while(条件表达式){循环体:} 当满足条件表达式时,执行循环体,之后继续验证是否满足条件表达式,满足继续执行循环体,之后重复,直到不满足条件表达式,循环结束.    先判断, ...

  9. java-从这里开始认识

    <java是什么:>Programming language 程序语言Development environment 开发环境Application environment 应用环境Dep ...

  10. 使用POI将doc文件转换为html

    需要的jar包有:有一些是依赖包,可以使用maven下载 doc文件转换为html文件 package com.gsww.sxzz.controller.service; import org.apa ...