luogu1095 Rye escape

topic

Title Description

Demon Hunter Illidan ambitious, he betrayed the night elves, led deep in the seabed of Naga attempted mutiny. Rye suffered a clash with Dian Wei Sha's trapped in a large barren island. In order to kill the Rye, Dian began to cast a spell on this island, the island will soon sink. By that time, everyone will be killed on the island. Rye running speed of 17m / S , at this rate can not escape the desert island. Fortunately Rye has a blink spell, may 1s move within 60m , but each time flashing spells consume mana 10 points. Magic Rye value of the speed of recovery is 4 Dian / S , in order to restore only place in the resting state.

Rye magic now known initial value M , the distance between the initial position and exit the island where he S , island sinking time T . Your task is to write a program to help figure out how to escape from a desert island Catcher in the shortest possible time, if not escape, the output Catcher in the remaining time can go the farthest distance. Note: Rye running, flicker or break activities are second (s) as a unit, and the duration of each activity is an integer seconds. Unit distance in meters (m) .

Input Format

Co-line, separated by a space including three non-negative integer M, S, T .

Output Format

A total of two lines.

The first 1 1 behavior string " Yes " or " No " (case sensitive), namely whether Rye flee the island.

Second 2 row 2 contains an integer. The first line " the Y E denotes Rye island escape when the minimum time S" (case insensitive); a first behavior " No represents Rye can go when the farthest distance" (case sensitive).

Sample input and output

Input # 1
39 200 4
Output # 1
No
197
Input # 2
36 255 10
Output # 2
Yes
6

Description / Tips

30% of the data satisfies: . 1 T . 1 0 , . 1 S . 1 0 0

50% of the data satisfies: . 1 T < . 1 0 0 0 , . 1 S . 1 0 0 0 0

100% data satisfies: . 1 T . 3 0 0 0 0 0 , 0 M . 1 0 0 0 , . 1 S . 1 0 . 8.

analysis

40 points wrongdoing

. 1      // m is uncertainty will blink every accumulation of a surplus, is not satisfied to some extent optimal subproblems 
2      for ( int I = . 1 ; I <= T; ++ I) {
 . 3          DP [I] = DP [I - . 1 ] + . 17 ;
 . 4          IF (m> = 10 ) DP [I] = DP [I - . 1 ] + 60 , m - = 10 ;
 . 5          the else {
 . 6              int CUR = . 1 , M1 = m; // magic further 1 second 
 7              // temporarily stored by m1, then m is not updated if constant 
. 8              the while (M1 < 10 ) ++ CUR, M1 + =4;
 9             if(i >= cur && dp[i] < dp[i - cur] + 60) dp[i] = dp[i - cur] + 60,m = m1 - 10;
10             //更新还要消耗m值 
11         }
12         if(dp[i] >= s){
13             puts("Yes");//大小写!!! 
14             put(i);
15             return;//要return 
16         } 
17     }
18     puts("No");
19     put(dp[t]);

 

Bad Code

 1 /*************************
 2 User:Mandy.H.Y
 3 Language:c++
 4 Problem:
 5 Algorithm:
 6 *************************/
 7 #include<bits/stdc++.h>
 8 
 9 using namespace std;
10 
11 const int maxt = 3e5 + 5;
12 
13 int m,s,t;
14 long long dp[maxt];
15 
16 char *TT,*mo,but[(1 << 15) + 2];
17 #define getchar() ((TT == mo && (mo = ((TT = but) + fread(but,1,1 << 15,stdin)),TT == mo)) ? -1 : *TT++) 
18 template<class T>inline void read(T &x){
19     x = 0;bool flag = 0;char ch = getchar();
20     while(!isdigit(ch)) flag |= ch == '-',ch = getchar();
21     while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
22     if(flag) x = -x;
23 }
24 
25 template<class T>void putch(const T x){
26     if(x > 9) putch(x / 10);
27     putchar(x % 10 | 48);
28 }
29 
30 template<class T>void put(const T x){
31     if(x < 0) putchar('-'),putch(-x);
32     the else Putch (X);
 33 is  }
 34 is  
35  void File () {
 36      The freopen ( " the Testdata (. 1) .in " , " R & lt " , stdin); 
 37 [  //     The freopen ( "1095.out", "W", stdout ); 
38 is  }
 39  
40  void ReadData () {
 41 is      Read (m); Read (S); Read (T);
 42 is  }
 43 is  
44 is  void Work () {
 45      // m is uncertainty will blink every the accumulation of a surplus, so the child does not meet the optimal problem to a certain extent
 46      // when considering multiple flashes of cumulative, multi-layer loop 
 47      //We pretreated flicker / blink several times, 
48      for ( int I = . 1 ; I <= T; ++ I) {
 49          IF (m> = 10 ) DP [I] DP = [I - . 1 ] + 60 , m - = 10 ;
 50          the else DP [I] DP = [I - . 1 ], m + = . 4 ;
 51 is      }
 52 is      
53 is      for ( int I = . 1 ; I <= T; ++ I) {
 54 is          DP [ I] = max (DP [I], DP [I - . 1 ] + . 17 );
 55          IF (DP [I]> = S) {
56             puts("Yes");
57             put(i);
58             return;
59         }
60     }
61     puts("No");
62     put(dp[t]);
63 }
64 
65 int main(){
66 //    file();
67     readdata();
68     work();
69     return 0;
70 }

 

Guess you like

Origin www.cnblogs.com/Mandy-H-Y/p/11363076.html