博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2017
阅读量:4599 次
发布时间:2019-06-09

本文共 2147 字,大约阅读时间需要 7 分钟。

Speed Limit
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 16884   Accepted: 11841

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

320 230 610 7260 130 5415 125 230 310 5-1

Sample Output

170 miles180 miles90 miles

Source

Mid-Central USA 2004
水,简单模拟,没什么好说的
1 #include 
2 #include
3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while(cin>>n) 9 {10 if(n==-1)11 break;12 int sum = 0,time,speed,oldtime=0;13 for(int i =0 ;i< n;i++)14 {15 scanf("%d%d",&speed,&time);16 sum += (time-oldtime)*speed;17 oldtime = time ;18 }19 cout<
<<" miles"<

 

转载于:https://www.cnblogs.com/jhldreams/p/3761351.html

你可能感兴趣的文章
docker swarm集群搭建
查看>>
选择排序
查看>>
SQLAlchemy
查看>>
BZOJ 1303: [CQOI2009]中位数图 问题转化_扫描_思维
查看>>
SP1026 FAVDICE - Favorite Dice 数学期望
查看>>
NodeJS、NPM安装配置步骤(windows版本)
查看>>
今日内容的回顾12
查看>>
js中字符串常用熟悉和方法
查看>>
【矩阵+十进制快速幂】[NOI2013]矩阵游戏
查看>>
Java一个简单的文件工具集
查看>>
蓝牙BLE扫描成功,log中打印出扫描到的设备
查看>>
React(v16.8.4)生命周期详解
查看>>
一般处理应用页中绑定方法代码段
查看>>
React组件Components的两种表示方式
查看>>
无限鼠标没反应了
查看>>
CSU - 1356 Catch(dfs染色两种写法,和hdu4751比较)
查看>>
zabbix监控php-fpm的性能
查看>>
温故知新 div + css笔记
查看>>
针对降质模型中的模糊SR
查看>>
ios开发学习笔记001-C语言基础知识
查看>>