一、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. debian切换sh shell到bash shell

    1 安装dpkg-reconfigure命令 切换到root账户即可. 2 dpkg-reconfigure dash 选择no

  2. ElasticSearch(十七)初识倒排索引

    现在有两条document: doc1:I really liked my small dogs, and I think my mom also liked them. doc2:He never ...

  3. android启动页延时跳转

    package com.goodness.goodness; import android.content.Context; import android.content.Intent; import ...

  4. pg 和sql server 分别如何新建二进制数据库字段以及插入二进制数据的sql语句

    PG create table demo ( id int, name bytea ); Insert into demo (id,name)values(256,pg_read_binary_fil ...

  5. SSH 占用数据库连接不释放问题

    SSH框架的项目在訪问数据库的时候.訪问完毕后一直占用链接,不释放.导致过了一段时间后,server没挂,就是有訪问数据库的连接是时候.一直卡住 解决的方法:   1.配置spring相应的hiber ...

  6. c的详细学习(9)结构体与共用体的学习(一)

    C语言提供了另外两种构造类型:结构体与公用体,用来存储若干个类型不同但彼此组成一个集合的数据总体. (1)结构体类型与结构体变量 1.定义 其一般形式为: struct  结构体类型名{ 数据类型1 ...

  7. [原创]Scala学习:Tuple,Array,Map ,文件操作

    1.Tuple:元祖.是一个有用的容器对象. 1)特点:  ① 元祖是不可变的,即,当声明完了一个元祖,那么它的长度就不可以在改变:  ② 元祖可以包含不同类型的数据,对象:   ③ 索引是从 '_1 ...

  8. grunt小教程

    本人的博客写了grunt的小教程,从零开始,一步一步的通过例子讲解,希望喜欢的同学给我的github上加颗星,谢谢! github地址: https://github.com/manlili/grun ...

  9. NLP-最小编辑距离

    最小编辑距离 一 概念 编辑距离(Edit Distance),又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的编辑操作次数.最小编辑距离,是指所需最小的编辑操作次数. 编辑操 ...

  10. Struts 2简介

    Struts 2简介 Struts 2 编辑 同义词 Struts2一般指Struts 2 Struts2是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet,在MVC设计模式中 ...