MT50. D塔2
描述
输入描述
第一行一个整数T,表示测试组数;输出描述
对于每组测试数据输出”YES”表示小明的英雄可以补到,”NO”表示不能。(输出不包括引号)示例1
输入:
1 3 1 1 1 1 1 1 1
输出:
YES
C++ 解法, 执行用时: 2ms, 内存消耗: 380KB, 提交时间: 2020-07-23
#include<iostream> #include<vector> using namespace std; int main() { int T=0; while(cin>>T) { int s=0, n=0, d=0,x=0,y=0,t0=0,t1=0,t2=0; for(int i=0;i<T;i++) { vector<pair<int,int>> dp={{2,0},{1,0},{0,0}}; cin>>s>>n>>d>>x>>y>>t0>>t1>>t2; int lastblood=3; while(s) { pair<int,int> w=dp[2]; if(w.first==0) { s-=n*d; w.second+=t0; } else if(w.first==1) { s-=y; w.second+=t1; } else { s-=x; w.second+=t2; } if(s<=0) { lastblood=w.first; break; } if(w.first==0) { int j=1; for(;j>=0;j--) { if(dp[j].second<w.second) dp[j+1]=dp[j]; else break; } dp[j+1]=w; } else { int j=1; for(;j>=0;j--) { if(dp[j].second<=w.second) dp[j+1]=dp[j]; else break; } dp[j+1]=w; } } if(lastblood==0) cout<<"NO"<<endl; else cout<<"YES"<<endl; } } }
C++ 解法, 执行用时: 2ms, 内存消耗: 504KB, 提交时间: 2020-08-22
#include <iostream> using namespace std; bool getGold(int s,int n,int d,int x,int y,int t0,int t1,int t2){ int bingTime = 0; int heroATime = 0; int heroJTime = 0; while(s > 0){ while(bingTime <= heroATime && bingTime <= heroJTime){ s -= n*d; if (s <= 0){ return false; } bingTime += t0; } while(heroATime < bingTime && heroATime <= heroJTime){ s -= x; heroATime += t2; if (s <= 0){ return true; } } while(heroJTime < bingTime && heroJTime <= heroATime){ s -= y; heroJTime += t1; if (s <= 0){ return true; } } } return false; } int main(){ int T; int s; int n,d,x,y; int t0,t1,t2; cin >> T; for(int i = 0;i<T;i++){ cin >> s; cin >> n; cin >> d; cin >> x; cin >> y; cin >> t0; cin >> t1; cin >> t2; bool can = getGold(s,n,d,x,y,t0,t1,t2); if (can){ printf("YES\n"); }else{ printf("NO\n"); } } return 0; }