Fzu 1076 crossing the desert

Source: Internet
Author: User

Crossing the desert

Time Limit: 1 s Memory limit: 32 m
Accepted submit205 Total submit304

A jeep arrived at a point on the side of the desert, X kilometers wide. Its fuel consumption was 1 litre/kilometer, and its total assembly volume was 500 litre. Generally, a jeep must use its own fuel tank to set several temporary oil storage points in the desert to cross the desert. If there is enough gasoline available at point A on the edge of the desert, then the jeep will consume at least a few liters of oil from point A through the desert to end B. WriteProgramTo calculate the minimum fuel consumption (accurate to three digits after the decimal point ).

(1) assume that the jeep does not fail when walking in the desert;
(2) The distance from a point on the desert edge to B is X 500 (that is, the desert width );

Input

The first line contains a positive integer k (1 <= k <= 6), indicating the number of test instances. Next to k rows, each row corresponds to a test example, containing a positive integer x, indicating the distance from point A to point B (1 <= x <= 2000 ).

Output

Each test sample corresponds to a line of output, containing a number, indicating the minimum fuel consumption.

Input example

25001000

Output example

500.0003836.497

Original:Fjnu preliminary 2005

Solution:

Reverse Modeling.

500 km before the end point, you can use L of oil directly to the end point. Therefore, the last fuel point is the first 500 kilometers before the end point, and the oil stored here is L. Push forward and backward, to store 500 l in the km, the first fuel point needs to store l, the process round-trip plus the number of one-way past, it is 3. Continue to explore .......

Detailed analysis: http://topic.csdn.net/t/20020906/13/1001713.html

 # Include <iostream> <br/> # include <iomanip> <br/> using namespace STD; </P> <p> int main () <br/>{< br/> int K, I; <br/> double Dist, oil; <br/> while (CIN> K) <br/>{< br/> while (k --) <br/>{< br/> CIN> Dist; <br/> dist-= 500; <br/> oil = 500.0; <br/> I = 1; <br/> while (Dist> 0) <br/>{< br/> dist-= 500.0/(2 * I + 1); <br/> I ++; <br/>}< br/> oil = oil * I + dist * (2 * i-1); <br/> cout <fixed <setprecision (3) <oil <Endl; <br/>}< br/> return 0; <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.