2020-05-22 — 习题训练二-D

D - Kana and Dragon Quest game

题意:龙最初有x点生命值,判断Kana是否可以使它的生命值小于等于0,Kana有俩种操作用来对付龙:

  • 虚空吸收,使用之后龙的生命值由原来的生命值h变成h/2 + 10
  • 雷击,使用之后龙的生命值由原来的生命值h变成h - 10
    Kana最多只能使用n次虚空吸收和m次雷击。

思路:可知当x>20时,虚空吸收降低的生命值更快,所以优先使用第一种操作,再进行第二种操作。

ac代码:

#include<iostream>
using namespace std;
int main(){
  int t,x,n,m,i;
  cin>>t;
  while(t--){
    cin>>x>>n>>m;
    for(i=0;i<n;i++){
      if(x<=20){
      break;
      }
      x=x/2+10;
    }
    x=x-10*m;
    if(x>0){
      cout<<"NO"<<endl;
    }
    else{
      cout<<"YES"<<endl;
    }
  }
  return 0;
}

 

原文地址:https://www.cnblogs.com/nanan/p/12941659.html