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