hdu-2059 Turtle and Rabbit race

Source: Internet
Author: User

Problem Description
It is said that in a long long time ago, poor rabbit experienced the biggest blow in life-the race lost to the turtle, heart depressed, vowed to avenge, so hid in the Hangzhou Xiasha Agricultural Park hardships painstaking practice, and finally practiced into a stunt, can not rest at a constant speed (VR m/s) has been running. The rabbit has been trying to find a chance to teach the turtle a shame before the snow.
Recently, HDU held the 50 anniversary celebration, the society's major celebrities gathered under the sand, the rabbit took the opportunity to challenge the turtle. Although the tortoise knew that the victory hope is not big, but under the pressure of public opinion, can accept the challenge.
The game is set on a straight road, the length of l meters, the rules are simple, who first reached the end of the victory.
Helpless turtle since the last victory, became a famous turtle, by some gossip magazine called "Animal Kingdom Liu Xiang", advertising constantly, at hand also has a lot of savings. In order to win the rabbit again, the turtle spent the most money to buy the most advanced weapons-"small Flying pigeon" brand electric vehicles. This car in the case of electricity can be VT1 m/s Speed "flying", but unfortunately the battery capacity is limited, each full of electricity can only travel the distance of C meters, after the foot to pedal, the turtle with the pedal speed of VT2 m/s. What's more, the turtle actually built many (n) power stations on the runway for the electric car to recharge. Where each charge takes a T-second time. Of course, turtles can choose to go or not recharge when they pass a charging station.
The game began immediately, and the hare and the tortoise with the electric electric car were standing at the starting line. Your task is to write a program, judge the turtle with the best plan to March, can win the constant speed of running rabbits.

Input
This topic contains multiple sets of tests, please handle to the end of the file. Each test consists of four rows:
The first line is a whole number L represents the total length of the runway
The second line contains three integer n,c,t, which indicates the number of charging stations, the distance the electric vehicle can travel after it has been flushed, and the time it takes to recharge each charge.
The third line is also three integer vr,vt1,vt2, respectively, indicating the speed of the rabbit running, turtle driving the speed of electric cars, turtle pedal electric car speed
The four lines contain N (n<=100) integer p1,p2...pn, respectively, representing the distance from the starting point of each charging station, where 0

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace STD;intMain () {DoubleL,C,T,VR,VT1,VT2;//defined as double type good calculation    Doubles[101];intNDoubledp[101];DoubleTIME,TIME1,SC; while(Cin&GT;&GT;L) {Cin>>n>>c>>t>>vr>>vt1>>vt2; TIME1=L/VR;//The time required for the rabbit to reach the finish line         for(intI=1; i<=n;i++)Cin>>s[i]; s[0]=0; s[n+1]=l; dp[0]=0;//0th charging station to 0 of the actual that         for(intI=1; i<=n+1; i++) {dp[i]=99999999;//First defined as Infinity             for(intj=0; j<i;j++) {sc=s[i]-s[j];distance of two charging stations                if(sc>c) time=c/vt1+ (sc-c)/vt2;ElseTIME=SC/VT1; TIME+=DP[J];if(j>0)//Origin does not need to add charging time.time+=t;            Dp[i]=min (Dp[i],time); }        }if(dp[n+1]&LT;TIME1)cout<<"What a pity rabbit!"<<endl;Else            cout<<"Good job,rabbit!"<<endl; }return 0;}

Dynamic programming problems, literally understand a bit of difficulty, given the variable too much, is what rabbit speed, turtle speed, what electric car speed, look too complex.
However, the actual grasp of the focus, the problem with the edge of the solution.
First rabbit to the end of the time is fixed, is L/VR, for the whole process of the turtle time, as long as the change of state to clear the line, we put the charging station divided into n+2, starting point and end count, Dp[i]=min (dp[i],time); Time indicates how long it takes the turtle to get to the first I charging station from the first J charging station.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu-2059 Turtle 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.