Hdu2059 Tortoise and rabbit race

Source: Internet
Author: User

Tortoise and hare race

Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 8705 accepted submission (s): 3348

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

Recommendlinle

Solution: this topic is about dynamic planning. It may be a bit confusing at first glance, it is easy for a child who is familiar with the general movement to calculate from the start point to the I + the time between one charging station. In this case, you only need to consider whether to charge at the I-th charging station. This is not the case. If the turtle starts driving after charging at the I-1 charging station, and the distance from the I-1 charging station to the I charging station is less than C, then, if your old program enables the tortoise to charge at the I and the charging station, you will not care about it. Otherwise, your old program will handle the step where the tortoise did not charge at the I-th charging station. Okay! The power of the house is still useless, so you just let the turtle crash the car to run (it will take more time), can it be good?
It should be, for the I-th charging station, calculated from the J-th charging station (j = 0; I <= n + 1; j ++) it takes the least time to start charging station I and the minimum sum from the start point to the charging station J. This avoids the mistakes mentioned above. When the tortoise arrives at the J-th charging station, the car still has no power. I will fill it with you and leave it again, so it will not be affected by the prerequisites.
State transition equation: time1 [I] = min (time1 [J] + temp, time1 [I]); (where (j = 0; I <= n + 1; j ++) temp is from the J-th charging station to the I-th charging station. If there is no electricity in the middle, the tortoise will open to the end.

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int main () {int L; int N, C, T; int VR, vt1, VT2; int station [105]; double time1 [105]; int I, j; while (scanf ("% d", & L )! = EOF) {scanf ("% d", & N, & C, & T); scanf ("% d", & VR, & vt1, & VT2); for (I = 1; I <= N; I ++) scanf ("% d", & station [I]); station [0] = 0; station [n + 1] = L; // process the start point and end point. Use the start point and end point as the charging station for direct processing (the start point does not require time for charging) for (I = 0; I <= n + 1; I ++) time1 [I] = 0 xfffffff; // The maximum integer time1 [0] = 0 for all time initialization; // the start time is only 0, no matter how for (I = 1; I <= n + 1; I ++) // for the I-th charging station, handle all the preceding charging stations {for (j = 0; j <I; j ++) // The minimum time used from the J-th charging station to the I-th charging station (the time used for current storage of the I-th charging station and the time used for charging from the J-th charging station to the I-th charging station) minimum value) // (charge from 0th charging stations to J The minimum time of the station has been obtained) {double temp; If (station [I]-station [J] <= C) // distance from the J-th charging station to the I-th charging station) (station [I]-station [J])/vt1; // note the precision else temp = (double) C/vt1 + (double) (station [I]-station [J]-C)/VT2; // pay attention to the accuracy if (j) // the Start Node does not charge timing temp + = T; time1 [I] = min (time1 [J] + temp, time1 [I]); // get minimum time} If (time1 [n + 1] <(double) l/VR) // less time for turtles {Note precision} printf ("what a pity rabbit! \ N "); else printf (" Good job, Rabbit! \ N ") ;}return 0 ;}

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.