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:
- the character attacks the monster, decreasing the monster's health by dCdC;
- the monster attacks the character, decreasing the character's health by dMdM;
- the character attacks the monster, decreasing the monster's health by dCdC;
- the monster attacks the character, decreasing the character's health by dMdM;
- 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;
}