DP [HDU 2059] 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): 11559 accepted submission (s): 4348

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 row 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 respectively, when an electric vehicle is fully powered, the distance it can travel and the time required for each charge. The third line is also three integers: vr, vt1, and VT2, indicating the speed at which rabbits run, the speed at which turtles drive electric vehicles. The fourth line of the speed at which turtles pedal electric vehicles 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 question data ensures that the turtles and rabbits will not arrive at the same time.

 

Sample input1003 20 55 8 210 40 601003 60 55 8 210 40 60

 

Sample outputgood job, Rabbit! What a pity rabbit!


Multi-stage decision-making, DP ,,,

 

#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define min(a,b) ((a)<(b)?(a):(b))#define INF 0x7ffffff#define N 110int l,n,c,t;int vr,vg,vb;double dp[N];int p[N];int main(){    int i,j;    while(scanf("%d",&l)!=EOF)    {        scanf("%d%d%d",&n,&c,&t);        scanf("%d%d%d",&vr,&vg,&vb);        for(i=1;i<=n;i++)        {            scanf("%d",&p[i]);        }        for(i=1;i<=n+1;i++)        {            dp[i]=INF;        }        dp[0]=0;        p[0]=0;        p[n+1]=l;        for(i=1;i<=n+1;i++)        {            for(j=0;j<i;j++)            {                int len=p[i]-p[j];                double time=0;                if(j) time+=t;                if(len<=c) time+=len*1.0/vg;                else time+=c*1.0/vg+(len-c)*1.0/vb;                time+=dp[j];                dp[i]=min(dp[i],time);            }        }        cout<<dp[n+1]<<‘ ‘<<l*1.0/vr<<endl;        if(dp[n+1]>l*1.0/vr)            cout<<"Good job,rabbit!\n";        else            cout<<"What a pity rabbit!\n";    }    return 0;}

 

DP [HDU 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.