原题:

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"

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

分析:

简单数学

源码:

#include<stdio.h> #define N 100 int main() {     int k;     int a[N],b[N];     b[0]=0;     while(scanf("%d",&k)&&(k!=-1))     {         int s=0;         for(int i=1; i<k+1; i++)         {             scanf("%d%d",&a[i],&b[i]);             s+=(b[i]-b[i-1])*a[i];         }         printf("%d miles\n",s);     }     return 0; }  

转载于:https://blog.51cto.com/bingsanchun/1271338

poj2017——Speed Limit相关推荐

  1. 2.1.1 Speed Limit

    #include <iostream> using namespace std; int main() {int n,i,x,y,z,ans;while(cin>>n& ...

  2. uboot 或者 linux 下限制 sata speed

    1.linux下通过  cmdline 实现 参考 :Documentation/admin-guide/kernel-parameters.txt libata.force= [LIBATA] Fo ...

  3. Toward a More Complete, Flexible, and Safer Speed Planning for Autonomous Driving via Convex Optimiz

    Toward a More Complete, Flexible, and Safer Speed Planning for Autonomous Driving via Convex Optimiz ...

  4. Baidu Apollo代码解析之EM Planner中的QP Speed Optimizer 1

    大家好,我已经把CSDN上的博客迁移到了知乎上,欢迎大家在知乎关注我的专栏慢慢悠悠小马车(https://zhuanlan.zhihu.com/duangduangduang).希望大家可以多多交流, ...

  5. ICPC程序设计题解书籍系列之五:吴永辉:《数据结构编程实验》(第2版)

    第1章 简单计算 UVALive2362 POJ1004 HDU1064 ZOJ1048 Financial Management[数学+水题] - 海岛Blog - CSDN博客 POJ1552 H ...

  6. 工厂用抽象类比接口_用简单的现实类比解释硬编码概念

    工厂用抽象类比接口 by Samer Buna 通过Samer Buna 用简单的现实类比解释硬编码概念 (Hard Coding Concepts Explained with Simple Rea ...

  7. 《自然》:修复AI神经网络的缺陷

    来源:王宏琳科学网博客 我在上一篇<海外观察>博客中,介绍了纽约大学马库斯教授和戴维斯教授的新书<重启 AI:构建我们可以信任的人工智能>和图灵奖得主朱迪亚•珀尔的著作< ...

  8. Linux_SquidProxyServer代理服务器

    目录 目录 Squid proxy server Web proxy server operating principle Squid features Setup squid server Setu ...

  9. 前端开发工程师如何在新的一年里提升自己

    大部分人非常在意个人在技术上的提升.但是保持对新技术的了解是一项不小的挑战, 毕竟我们需要的信息在数量上过于庞大.2012年里,伴随着前端发展的是大量的革命性突破和对前端的重新定义. 我们在实践的路上 ...

最新文章

  1. OpenSSL使用指南
  2. 035_jdbc-mysql-dbutils的使用
  3. UA MATH567 高维统计I 概率不等式2 在Erdős–Rényi随机图模型中的应用
  4. 一文读懂分布式架构知识体系(内含超全核心知识大图)
  5. 酷睿i7cpu适合的linux,CPU性能篇 - Core i7-4770K Linux之旅:有喜有忧_Linux新闻_Linux公社-Linux系统门户网站...
  6. 字节流抽象类 java
  7. 谈谈Winform程序的界面设计
  8. .Net中的加密解密
  9. 《『若水新闻』客户端开发教程》——12.代码编写(4)
  10. JAVA实现显示指定类型的文件的例子
  11. Extjs5.0从入门到实战开发信息管理系统视频教程
  12. 中国通信简史 (上)
  13. sqoop与PG库导入导出数据
  14. GAE+bottle+jinja2+beaker快速开发demo - Python,GAE - language - ITeye论坛
  15. IT人物TOP100英雄人物榜
  16. 光栅图形学(一)——直线段的扫描转换算法
  17. 公司章程如何设计规避股权纠纷
  18. js绑定onblur事件
  19. 机器学习-增量训练方法
  20. B站后台源代码泄露,官方回应声明黑话指南

热门文章

  1. CentOS7 64位下MySQL5.7安装与配置
  2. 141. Linked List Cycle
  3. 17秋 软件工程 第六次作业 Beta冲刺 总结博客
  4. php判断多维数组的技巧
  5. HDU 5119 Happy Matt Friends ——(背包DP)
  6. Linux快捷键-命令行下
  7. MSMQ(Microsoft Message Queue)介绍
  8. 如何让Unity支持中文
  9. 修改MSSQLServer的登陆方式
  10. 02.Python网络爬虫第二弹《http和https协议》