Cave escape
Describe:
The Elf Prince loves Adventure, and in an adventure he enters a mysterious cave. In the depths of the cave, the elf prince accidentally touches the hidden organs in the cave, and the whole cave will soon collapse, and the fairy Prince must flee the cave as soon as possible. The Elf Prince runs at a speed of 17m/s and may not escape from the caves at such a rate. Fortunately, the Fairy Prince has a flashing spell that can move 60m within 1s, but each use of a flashing spell consumes a mana value of 10 points. The magic value of the Elf Prince recovers at a speed of 4 points/s, which can only be resumed when resting in situ.
Now known as the Elf Prince's magical initial value m, the location of the cave in which he is located is the distance between the cave exit S, and the time t from the cave collapse. Your task is to write a program to help the Elf Prince calculate how to escape the caves in the shortest possible time. If you can escape, output "Yes", and output the shortest time to escape, if not escape, then output "No", and output the fairy Prince in the remaining time to walk the farthest distance. Note The letter is case-sensitive. Note: The elf Prince runs, flashes, or breaks in seconds (s). and the duration of each activity is an integer second. The unit of distance is in meters (m).
Note: M, S, t are integers greater than or equal to 0. The input guarantees the legitimacy of the value, the examinee does not check.
Remind:
If the input s is 0, the description itself is already in the exit and the output should be: Yes 0
If the input T is 0 (and S is not 0), then there is no time, the output should be: no 0
Run time limit: Unlimited
Memory Limit: Unlimited
Input:
Input format:
M
S
T
Output:
Output format:
Yes the shortest time to escape from the caves
Or
The farthest distance that No can escape before the cave collapses
Sample input:
10
50
5
Sample output:
Yes 1
The following code did not submit OJ validation, welcome to the exchange:
#include <iostream> #include <string> #include <cstdio> #include <cstdlib> #include < algorithm> #include <cstring> #include <queue>using namespace Std;int mintime, Largestdis;int m,s,t;void DFS (int dis, int m, int time) {if (time <= t) {Largestdis = dis > Largestdis?dis:largestdis;} if (dis >= s) {mintime = time < Mintime?time:mintime;return;} if (M >=) {dfs (dis+60, m-10, time+1);} Else{dfs (dis+17, M, time+1);d fs (Dis, m+4, time+1);}} int main () {//int m,s,t;while (cin>>m>>s>>t) {mintime = Int_max;largestdis = Int_min;if (s = = 0) {cout < ;< "Yes" << 0 << endl;continue;} else if (t ==0 && s! = 0) {cout << "No" << 0 << endl;continue;} DFS (0,m,0); if (Mintime <= t) {cout<< "Yes" << "<<MINTIME<<ENDL;} else cout<< "No" << "" <<LARGESTDIS<<ENDL;} System ("pause"); return 0;}