Hdu2059 Tortoise and rabbit race [DP]

Source: Internet
Author: User

Tortoise race time limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others) Total submission (s): 11540 accepted submission (s): 4337

Problem description it is said that a long time ago, the poor rabbit experienced the biggest blow in his life-after losing to the tortoise in a race, he was depressed and vowed to report revenge, so I hid in a agriculture park in Xiasha, Hangzhou, and learned how to practice it with treasure, so that I could keep running at a constant speed (VR m/s) without having to rest. The rabbit has been trying to find a chance to teach the tortoise a lesson.
Recently, the 50 Anniversary of HDU was celebrated. Celebrities gathered in the sand and rabbits took the opportunity to challenge turtles. Although the tortoise knows that there is little hope for victory, he can only accept the challenge due to public opinion pressure.
The game is located on a straight road with a length of L meters. The rule is very simple. Whoever reaches the end will win.
But since the victory, the tortoise has become a tortoise, and some gossip magazines call it "Liu Xiang of the animal community". The advertisement keeps on, and there is a lot of savings on hand. In order to win the rabbit again, the tortoise bought the most advanced weapon-the "Little Pigeon" brand electric car. This car is capable of "speeding" at the vt1 Mbit/s speed when there is electricity. Unfortunately, the battery capacity is limited, and each power-on car can only drive a distance of C meters at most, in the future, you can only use your feet to pedal. When the tortoise uses the pedal, the speed is VT2 M/s. Even more, turtles have built many (n) power supply stations on the runway to charge their own electric vehicles. It takes t seconds for each charge. Of course, when the tortoise passes through a charging station, they can choose to or not charge.
The competition started immediately, and the rabbit and the electric-powered turtle stood at the starting line. Your task is to write a program to determine whether the tortoise can win a rabbit that has been running at a constant speed when using the best solution.
Input this question contains multiple groups of tests, please process until the end of the file. Each test includes four rows:
The first line is an integer l representing the total length of the runway
The second row contains three integers, N, C, and T, indicating the number of charging stations, the distance the electric vehicle can travel after it is fully powered, and the time required for each charging.
The third line also contains three integers: vr, vt1, and VT2, indicating the speed at which rabbits run, the speed at which turtles drive electric vehicles, and the speed at which turtles pedal electric vehicles.
The fourth row contains n (n <= 100) integers P1, p2... pn, indicating the distance between each charging station and the start point of the runway, where 0 <P1 <P2 <... <PN <L
Each number is within the 32-bit integer range.
 
Output: When the tortoise may win, output a line "what a pity rabbit! ". Otherwise, output a line of "Good job, Rabbit! ";
The problem data ensures that the turtles and rabbits arrive at the same time.
Sample Input
1003 20 55 8 210 40 601003 60 55 8 210 40 60
 
Sample output
Good job,rabbit!What a pity rabbit!
 
Authorlinle
Source celebration Cup warm up this question began to think about using greedy solutions, the end of the station as the last charging station, DP [I] represents the minimum time to reach the I charging station, DP [I] = min (not charging at the I-1, charging at the i-1), but this idea is wrong, this solution seems to be the best, in fact, the shortest time to reach the I charging station is not only determined by the charging station of the I-1 charging station, but also by the former charging station, so that it does not meet the greedy conditions. Then I changed my mind and asked DP [I] to add a gotime internally as the departure time point when the tortoise arrived at the end of the gas station I, toend indicates the time from the start point to the end point. In this way, the shortest time for reaching the I-th charging station can be obtained. The time for reaching the end point is fixed and the final answer is obtained. The second approach is better than the first approach, that is, when the first charging station is reached, it is concluded that all the above charging stations are taken into account, not just the former charging station adjacent to it, this solution is the real optimal solution.

# Include <stdio. h> # include <string. h ># define maxn 105 # define INF 0x3f3f3f3fstruct node {double gotime, toend;} DP [maxn]; // DP [I] indicates that int arr [maxn], L, N, C, T, VR, vt1, and VT2 are used as the final gas station; double min (double A, double B) {return a <B? A: B;} double caltime (INT Dist) {If (Dist <= c) Return (double) Dist/vt1; Return (double) (Dist-C) /VT2 + (double) C/vt1;} int main () {// freopen ("stdin.txt", "r", stdin); double ans; while (~ Scanf ("% d", & L) {scanf ("% d", & N, & C, & T ); scanf ("% d", & VR, & vt1, & VT2); For (INT I = 1; I <= N; ++ I) scanf ("% d", & arr [I]); arr [0] = 0; arr [n + 1] = L; DP [0]. gotime = 0.0; ans = DP [0]. toend = DP [0]. gotime + caltime (ARR [n + 1]-Arr [0]); For (INT I = 1; I <= N; ++ I) {DP [I]. gotime = inf; For (Int J = 0; j <I; ++ J) {DP [I]. gotime = min (DP [I]. gotime, DP [J]. gotime + caltime (ARR [I]-Arr [J]);} DP [I]. toend = (DP [I]. gotime + = t) + caltime (ARR [n + 1]-Arr [I]); ans = min (ANS, DP [I]. toend);} If (ANS <(double) L/VR) printf ("what a pity rabbit! \ N "); else printf (" Good job, Rabbit! \ N ") ;}return 0 ;}


Hdu2059 Tortoise and rabbit race [DP]

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.