杭电ACM HDU 3424 Range

Range

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 245    Accepted Submission(s): 153


Problem Description
Some automobiles display the estimated driving range, that is, the distance you can expect to drive it (without adding fuel) before running out of fuel. Here is how it works: periodically, the vehicle's computer records the odometer reading and the weight of fuel in the fuel tank. From this data, the fuel consumption over a certain distance can be computed.
From the fuel consumption and the most recent measurement of fuel tank contents (which we assume is current for all practical purposes), the range can be calculated. Intervals over which the quantity of fuel increased (fuel was added to the tank) will not be used in the computations. For example, in the first problem instance of the sample input, the interval where the fuel weight increased from 29.9 kilograms to 34.2 kilograms will not be used. In this example, 16.3 kilograms of fuel were consumed over a distance of 228.6
kilometers. Therefore, the most recently measured fuel contents of 31.2 kilograms will enable you to drive another 438 kilometers (rounded to the nearest integer). The input will always contain at least one interval (two consecutive lines of input) where no fuel was added to the tank.
 


 

Input
The input contains data for a number of problem instances. Each problem instance consists of three or more (odometer reading, fuel weight) pairs, one pair per line. Distances are measured in kilometers and fuel weight in kilograms. All input numbers will be given to one decimal place. The end of each problem instance will be signaled by a (0.0, 0.0) pair. The last problem instance will be followed by a (-1.0, -1.0) pair.
 


 

Output
For each problem instance, print the range, rounded to the nearest integer.
 


 

Sample Input
  
  
18400.5 43.2 18440.4 40.4 18482.7 37.0 18540.2 33.1 18585.3 29.9 18620.8 34.2 18664.6 31.2 0.0 0.0 18400.5 43.2 18440.4 40.4 18482.7 37.0 18540.2 33.1 18585.3 29.9 0.0 0.0 -1.0 -1.0
 


 

Sample Output
  
  
438 415
 


 

Source
 


 

Recommend
zhouzeyong
 


 

 

#include <cstdio>
#include <cmath>
using namespace std;
#define F(x) abs(x)>1e-6
int main(){
    double x,y,a,b,s,f;
    while(scanf("%lf%lf",&x,&y)&&(F(x+1.0)||F(y+1.0))){
        s=f=0;
        while(scanf("%lf%lf",&a,&b)&&(F(a)||F(b))){
            if(b<y){
                s+=a-x;f+=y-b;
            }
            x=a;y=b;
        }
        printf("%.0lf\n",s/f*y);
    }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值