HDU 2095 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): 8513 accepted submission (s): 3271

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
 

For more information about the recommendlinle algorithm, see code comments.

# Include <iostream> # include <stdio. h> # include <string. h> using namespace STD; double dis [110]; // record distance: int N, C, T; double VR, vt1, VT2, L, temp, mi; double best [110], cost [110] [110]; int main () {int I, j, k; while (~ Scanf ("% lf", & L) {scanf ("% d", & N, & C, & T ); scanf ("% lf", & VR, & vt1, & VT2); memset (Best, 0, sizeof best); memset (cost, 0, sizeof cost); DIS [0] = 0; for (I = 1; I <= N; I ++) scanf ("% lf", & dis [I]); dis [I] = L; n ++; for (I = 0; I <= N; I ++) // pre-processing calculates the time used from I power-on to other points {for (j = I + 1; j <= N; j ++) {temp = dis [J]-Dis [I]; // calculate the two-point distance from if (C> = temp) cost [I] [J] = temp/vt1; // else cost [I] [J] = C/vt1 + (temp-C)/VT2; if (I! = 0) cost [I] [J] + = T ;}} for (I = 1; I <= N; I ++) {mi = cost [0] [I]; for (k = 1; k <I; k ++) if (best [k] + cost [k] [I] <mi) MI = Best [k] + cost [k] [I]; // recursive calculation. If the optimal solution to the I point is obtained by adding the power at the K point, the best [I] = Best [k] + cost [k] [I]. so k can obtain the shortest time of I: Best [I] = mi;} If (best [N] <L/VR) 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.