Range

Range
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 52, Accepted users: 47
Problem 11769 : No special judgement
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

做了几次湖大的练习赛,每次反正只能AC一个。湖大的题目有点不好的是:明明一个简单的题目,硬要用大段的无所谓的英文来描述。这个题目在比赛的时候我用结构体保存每一个数,然后判断是不是加油了,后来经cl提醒,不能保存数据,因为输入的数据是未知的,只能输入一组就处理一组。经过后来的思考,终于把这个题目AC了,还是后来cl指出我的代码的一个小bug菜AC的。

#include<iostream> using namespace std; int main() { double d,k,dsum=0,ksum=0,dd=0,kk=-1; while(1) { while(cin>>d>>k&&(d+k)) { if(d+k==-2) return 0; if(k<kk)//将kk设为-1使得第一组数据不处理,后面判断是否加油了,加油了也不处理。 { dsum +=d-dd; ksum +=kk-k; } dd=d; kk=k; } cout<<int(((dsum/ksum)*kk)+0.5)<<endl; dsum=0; ksum=0; kk=-1;//这里就是cl指出的bug } return 0; }

 

你可能感兴趣的:(Range)