codeforces round#122:Div2:Problem C:kill the monster

C. Kill the Monster

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Monocarp is playing a computer game. In this game, his character fights different monsters.

A fight between a character and a monster goes as follows. Suppose the character initially has health hChC and attack dCdC; the monster initially has health hMhM and attack dMdM. The fight consists of several steps:

  1. the character attacks the monster, decreasing the monster's health by dCdC;
  2. the monster attacks the character, decreasing the character's health by dMdM;
  3. the character attacks the monster, decreasing the monster's health by dCdC;
  4. the monster attacks the character, decreasing the character's health by dMdM;
  5. and so on, until the end of the fight.

The fight ends when someone's health becomes non-positive (i. e. 00 or less). If the monster's health becomes non-positive, the character wins, otherwise the monster wins.

Monocarp's character currently has health equal to hChC and attack equal to dCdC. He wants to slay a monster with health equal to hMhM and attack equal to dMdM. Before the fight, Monocarp can spend up to kk coins to upgrade his character's weapon and/or armor; each upgrade costs exactly one coin, each weapon upgrade increases the character's attack by ww, and each armor upgrade increases the character's health by aa.

Can Monocarp's character slay the monster if Monocarp spends coins on upgrades optimally?

Input

The first line contains one integer tt (1≤t≤5⋅1041≤t≤5⋅104) — the number of test cases. Each test case consists of three lines:

The first line contains two integers hChC and dCdC (1≤hC≤10151≤hC≤1015; 1≤dC≤1091≤dC≤109) — the character's health and attack;

The second line contains two integers hMhM and dMdM (1≤hM≤10151≤hM≤1015; 1≤dM≤1091≤dM≤109) — the monster's health and attack;

The third line contains three integers kk, ww and aa (0≤k≤2⋅1050≤k≤2⋅105; 0≤w≤1040≤w≤104; 0≤a≤10100≤a≤1010) — the maximum number of coins that Monocarp can spend, the amount added to the character's attack with each weapon upgrade, and the amount added to the character's health with each armor upgrade, respectively.

The sum of kk over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print YES if it is possible to slay the monster by optimally choosing the upgrades. Otherwise, print NO.

做法:贪心。

不论是以血量还是其他形式,本质上来讲还是根据能够行动的回合数来确定我们的答案的,假设主角可以进攻A回合,怪物能进攻B回合,能进攻的前提是血量还未减到非整数,这种情况下,谁的可行动回合数最多,谁就是胜者。

代码实现:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
 
ll tt;
ll hc,dc,hm,dm,a,w,k;

int main(){
	cin>>tt;
while(tt--)
{
	ll f=0;
	ll cm,mc;
  cin>>hc>>dc>>hm>>dm>>k>>w>>a;
    for(int j=0;j<=k;j++)
    {
      ll h=hc+a*j;
	  ll d=dc+w*(k-j);
	  cm=(hm-1+d)/d;
	  mc=(h-1+dm)/dm;
	  if(cm<=mc) 
	  {
	  	   cout<<"YES"<<endl;
	       f=1;
	       break;
	  	
	  }
    	
	}
    if(!f)  cout<<"NO"<<endl;
    	
  }

    
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

litian355

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值