Yes 1
以下代码未提交OJ验证,欢迎交流指正:
#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 >= 10) { dfs(dis+60, m-10, time+1); } else{ dfs(dis+17, m, time+1); dfs(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; }
原文地址:http://blog.csdn.net/xiaozhuaixifu/article/details/25302069