一、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. 九度OJ 1346:会员积分排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:967 解决:413 题目描述: 元旦佳节快到了,超市A想要给会员一些奖品.但是奖品有限,所以它需要给这些会员做一个排序,然后将名单输出来.排 ...

  2. 九度OJ 1340:小A的计算器 (进制转换)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:735 解决:202 题目描述: 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-2 ...

  3. Python学习笔记_Python基础

    Python 基础 语句和语法 凝视 继续 代码组 代码的缩进 在一行书写多个语句 模块 变量赋值 赋值操作符 增量赋值 多重赋值 多元赋值 python编写的基本风格 模块的结构和布局 内存管理 变 ...

  4. 在Ubuntu安装go编译环境

    在Ubuntu安装go编译环境 好记性不如烂笔头,所以趁热打铁记录下golang编译环境的安装过程. 首先下载一些依赖包: sudo apt-get install bison ed gawk gcc ...

  5. scala语法解析(解码指环)

    看惯了JAVA的语法,再看scala的语法,有的晦涩难懂.正好遇到一个介绍scala语法的文章,就直接截图留念.省的再临时抱佛脚了.

  6. Zookeeper启动Permission denied

    Zookeeper 查询状态,出现如下问题: JMX enabled by default Using config: /usr/zookeeper/zookeeper-/bin/../conf/zo ...

  7. c++学习笔记(网上资料)

                                    C++笔记       2007-3-22 1. 程序 —— 可执行文件,人发送给计算机的一组指令.         硬件指令是二进制, ...

  8. P4045 [JSOI2009]密码

    题目 P4045 [JSOI2009]密码 做法 AC自动机+状压+爆搜 建AC自动机是显然的,顺便预处理\(lst_i\)表示\(i\)结点以哪些串结束(二进制) 然后跑状压\(dp[i][j][k ...

  9. web前端框架之自定义form表单验证

    自定义form验证初试 .在后端创建一个类MainForm,并且在类中自定义host ip port phone等,然后写入方法,在post方法中创建MainForm对象,并且把post方法中的sel ...

  10. 为什么要用redux?component自身管理自己的state难道不更解耦吗?

    这是前几天百度2面的时候,面试官问我的一个问题.说实话当时有点紧张,其实也没去细想,本身react我就学了2个多星期,虽然看过redux这些源码,不过这个问题好像我从来没想过. 那其实react官网本 ...