Given a rule to ask the result of a race, the question is when the tortoise chooses to charge.
Solution: because there are only 100 charging stations at most, the decision affecting the result takes place in each charging station. Therefore, you only need to consider the strategy to be adopted when arriving at the charging station. You only need to retain the optimal value for a certain station and charge it.
The Code is as follows:
# Include <iostream> # include <algorithm> using namespace STD; // if the two nodes are connected to the edge, class rule {public: static int n must be added to the points on the arc head; // Number of charging stations static int VR, vt1, VT2; // three speed values static int efar; // The distance between the charging station and the static int ETI; // The charging time is static int length; // The length of the track}; int rule: vr, rule: vt1, rule: VT2, rule: N; int rule:: efar, rule: ETI, rule: length; Class node {PRIVATE: int X; // double Ti at the coordinate position; // bool vis; // Whether the point has reached public: node () {vis = false;} int getx () const {return X;} double getti () const {return Ti;} bool getvis () const {return vis;} void setx (INT v) {x = V;} void setti (Double V) {Ti = V;} void setvis (bool V) {vis = V;} void read () {CIN> X;} // read the position of the charging station: Friend double cost (const node &, const node &) ;}; double cost (const node & A, const node & B) {int Dist = B. getx ()-. getx (); If (Dist <= Rule: efar) return rule: ETI + (1.0 * Dist/rule: vt1); else return rule: ETI + (1.0 * Rule: efar/rule:: vt1 + 1.0 * (Dist-rule: efar)/rule: VT2);} void solve (node Nd [], int maxn) {for (INT I = 0; I <= rule: N; ++ I) {// enumeration starts if (! Nd [I]. getvis () continue; // If the vertex has not been updated, it will not update other vertices for (Int J = I + 1; j <maxn; ++ J) {// The Point J that can be reached from point I is the point if (Nd [J]. getvis () {// if this point has been accessed by Nd [J]. setti (min (Nd [J]. getti (), Nd [I]. getti () + cost (Nd [I], Nd [J]);} else {Nd [J]. setti (Nd [I]. getti () + cost (Nd [I], Nd [J]); Nd [J]. setvis (true) ;}}} bool win (node Nd []) {double A = 1.0 * Rule: length/rule: vr; Double B = Nd [Rule:: n + 1]. getti ()-R Ule: ETI; return B <A;} int main () {While (CIN> rule: length) {CIN> rule: n> rule :: efar> rule: ETI; CIN> rule: vr> rule: vt1> rule: VT2; const int maxn = rule: n + 2; node Nd [maxn]; // call the initialization function for each data record (INT I = 1; I <= rule: N; ++ I) {Nd [I]. read ();} Nd [0]. setx (0); // construct the start point and end point Nd [0]. setti (0.0); Nd [0]. setvis (true); Nd [Rule: n + 1]. setx (rule: length); solve (Nd, maxn); cout <(WIN (ND)? "What a pity rabbit! \ N ":" Good job, Rabbit! \ N ") ;}return 0 ;}