Hangzhou electric 2059 Tortoise and rabbit race

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2059

We need to enter

(1) L

(2) N, C, T;

(3) VR, V1, V2;

(4) P [1], p [2], p [3], p [N];

We need to compare the rabbit time with the turtle time.

Rabbit: 1.0 * l/VR;

Tortoise:

The time of the tortoise is obtained by the meaning of the question, which requires the shortest. Therefore, we only need to find the num time from the tortoise to the end, and find the shortest time in the num time.

For example, there are four different ways for turtles to go from gas station 1 to gas station 4.

1---2---3---4;

1---2---4;

1---4;

1---3---4;

If the turtle is required to calculate the shortest time from the gas station 1 to the gas station 4, calculate the time of the four different steps separately and take the minimum value.

Similarly, the total time from the first station to the second station is what you want. Here we can use the for loop statement to process it.

In this way, the shortest time required by the tortoise is calculated.

# Include <stdio. h> int main () {int L, N, C, T, VR, V1, V2, P [105], I, j, Len; double min, e, DP [105]; while (scanf ("% d", & L )! = EOF) {scanf ("% d", & N, & C, & T); scanf ("% d", & VR, & V1, & V2); for (I = 1; I <= N; I ++) scanf ("% d", & P [I]); P [0] = 0; P [I] = L; DP [0] = 0; for (I = 1; I <n + 2; I ++) {min = 0 xffffff; For (j = 0; j <I; j ++) {Len = P [I]-P [J]; E = C> Len? 1.0 * Len/V1: C * 1.0/V1 + (LEN-C + 0.0)/V2; e + = DP [J]; // Add the time for the first J sites if (j) e + = T; // The time required for refueling if (min> E) min = E ;} DP [I] = min; // the shortest time to the station I} If (1.0 * l/VR> DP [n + 1]) printf ("what a pity rabbit! \ N "); elseprintf (" Good job, Rabbit! \ N ");}}

  

 

Hangzhou electric 2059 Tortoise and rabbit race

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.