The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序

简介: The Great Hero(Codeforces Round #700 (Div. 2))模拟+贪心思想和排序

The great hero guards the country where Homer lives. The hero has attack power AA and initial health value BB . There are nn monsters in front of the hero. The ii -th monster has attack power a_iai and initial health value b_ibi .


The hero or a monster is said to be living, if his or its health value is positive (greater than or equal to 11 ); and he or it is said to be dead, if his or its health value is non-positive (less than or equal to 00 ).


In order to protect people in the country, the hero will fight with monsters until either the hero is dead or all the monsters are dead.


In each fight, the hero can select an arbitrary living monster and fight with it. Suppose the ii -th monster is selected, and the health values of the hero and the ii -th monster are xx and yy before the fight, respectively. After the fight, the health values of the hero and the ii -th monster become x-a_ix−ai and y-Ay−A , respectively.


Note that the hero can fight the same monster more than once.


For the safety of the people in the country, please tell them whether the great hero can kill all the monsters (even if the great hero himself is dead after killing the last monster).


输入格式



Each test contains multiple test cases. The first line contains tt ( 1 \le t \le 10^51≤t≤105 ) — the number of test cases. Description of the test cases follows.


The first line of each test case contains three integers AA ( 1 \leq A \leq 10^61≤A≤106 ), BB ( 1 \leq B \leq 10^61≤B≤106 ) and nn ( 1 \leq n \leq 10^51≤n≤105 ) — the attack power of the great hero, the initial health value of the great hero, and the number of monsters.


The second line of each test case contains nn integers a_1, a_2, \dots, a_na1,a2,…,an ( 1 \leq a_i \leq 10^61≤ai≤106 ), where a_iai denotes the attack power of the ii -th monster.


The third line of each test case contains nn integers b_1, b_2, \dots, b_nb1,b2,…,bn ( 1 \leq b_i \leq 10^61≤bi≤106 ), where b_ibi denotes the initial health value of the ii -th monster.


It is guaranteed that the sum of nn over all test cases does not exceed 10^5105 .


输出格式



For each test case print the answer: "YES" (without quotes) if the great hero can kill all the monsters. Otherwise, print "NO" (without quotes).


题意翻译



题意


我们定义一个人物为一个二元组 (x,y), 称其中 x  为攻击力, y 为血量. 一个英雄是一个人物. 现在有 n  个怪物, 每个怪物是一个人物. 我们这样定义两个人物  A 与  B 交战:


  • A  的血量减少等同于 B 的攻击力的数值,  B 的血量也减少等同于  A 的攻击力的数值.
  • 然后, A  和  B 中所有血量小于等于 0  的人物死亡.


  • 现在英雄需要消灭所有怪物, 消灭怪物的方式是与之交战. 请求出英雄能不能消灭所有的怪物, 即使英雄本人在消灭所有怪物后死亡.


输入格式


第一行包含一个正整数   T(1≤T≤105), 表示有 TT 组测试数据.


接下来第  3k−2 行, 包括第 kk 组数据中, 英雄的攻击力 A  (1≤A≤106), 血量  B(1≤B≤106), 怪物个数  n(1≤n≤105).


接下来第  3k−1 行, 包括对于每个 i∈[1,n] 第  k 组数据中第 i 个怪物的攻击力 ai(1≤ai≤106).


接下来第  3k 行, 包括对于每个  i∈[1,n] 第  k 组数据中第  i 个怪物的血量 bi(1≤bi≤106).


所有数据的  n 的总和小于等于 10^5  


输出格式


对于每组测试数据, 输出仅一行一个字符串 "YES"(如果英雄能够杀死所有怪物) 或 "NO"(如果英雄不能杀死所有怪物) (不包括括号).


输入输出样例



输入 #1复制

5
3 17 1
2
16
10 999 3
10 20 30
100 50 30
1000 1000 4
200 300 400 500
1000 1000 1000 1000
999 999 1
1000
1000
999 999 1
1000000
999


输出 #1复制

1. YES
2. YES
3. YES
4. NO
5. YES


说明/提示



In the first example: There will be 6  fights between the hero and the only monster. After that, the monster is dead and the health value of the hero becomes  17−6×2=5>0 . So the answer is "YES", and moreover, the hero is still living.


In the second example: After all monsters are dead, the health value of the hero will become 709 regardless of the order of all fights. So the answer is "YES".


In the third example: A possible order is to fight with the 11 -st,  2 -nd, 3  -rd and 44 -th monsters. After all fights, the health value of the hero becomes -400 . Unfortunately, the hero is dead, but all monsters are also dead. So the answer is "YES".


In the fourth example: The hero becomes dead but the monster is still living with health value 1000 - 999 = 1  . So the answer is "NO".


解题思路;


先打血量小、攻击力小的怪物,再打其他的。


注意判断,注意细节。


判断分情况讨论:


  • 当正在打的不是最后一个怪物时,若打完后血量 <=0 则输出 NO
  • 当正在打的是最后一个怪物时,若打完后血量 + an≤0 则输出 NO
  • 否则输出 YES


具体实现看ac代码;

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long 
const ll maxn=1e6+7;
struct node{
  ll a,b;
}p[maxn];
bool cmp(node q,node w)
{
  return q.a==w.b?q.b<w.b:q.a<w.a; 
}
int main()
{
  int t;
  cin>>t;
  while(t--)
  {
    ll A,B,D,n;
    int b=0;
    cin>>A>>B>>n;//英雄攻击,血量,怪物个数 
    for(int i=1;i<=n;i++)cin>>p[i].a;//怪物攻击 
    for(int i=1;i<=n;i++)cin>>p[i].b;//怪物血量 
    sort(p+1,p+1+n,cmp);//排序,按照攻击由小到大排,如果攻击相同就按照血量低的排在前面。 
      for(int i=1;i<=n;i++)
      {
      ll C=ceil(1.0*p[i].b/A);//向上取整 就是相当于可以承受英雄多少次攻击 
        ll D=p[i].a*C;//怪兽攻击英雄的血量 
      B-=D;
      if(B<=0&&i<n){//这个意思就是英雄倒下了,但是怪兽还存在 
        b=1;
        cout<<"NO"<<endl;
      break;
      }
      if(i==n&&B<0&&B+p[i].a<=0)//英雄到了最后一个怪兽但是自己却没有杀死这个怪兽 ,
      {//第三个式子的意思是英雄其实多被怪兽砍了好几刀,意思就是英雄并没有杀死怪兽
        b=1;
        cout<<"NO"<<endl;
       break;
      }
      }
      if(!b)
      cout<<"YES"<<endl;
  }
}
相关文章
|
安全 Shell Linux
【Shell 命令集合 磁盘管理 】Linux 磁盘分区工具 fdisk命令使用教程
【Shell 命令集合 磁盘管理 】Linux 磁盘分区工具 fdisk命令使用教程
464 0
|
移动开发 弹性计算 缓存
阿里云服务器上如何部署 H5 游戏?
在自学游戏开发的路上,最有成就感的时刻就是将自己的小游戏做出来分享给朋友试玩,原生的游戏开可以打包分享,小游戏上线流程又长,那 H5 小游戏该怎么分享呢?本文就带大家通过 nginx 将构建好的 H5 游戏托管的阿里云上。
阿里云服务器上如何部署 H5 游戏?
|
存储 网络安全 文件存储
NAS与云存储哪个更适合家庭使用?
【6月更文挑战第30天】NAS与云存储哪个更适合家庭使用?
973 58
|
敏捷开发 测试技术 API
阿里云云效产品使用问题之如何通过API查询指定人在指定时间内提交了多少行代码
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
【通信协议讲解】单片机基础重点通信协议解析与总结之IIC(一)
【通信协议讲解】单片机基础重点通信协议解析与总结之IIC(一)
175 1
|
缓存 监控 Java
(十)深入理解Java并发编程之线程池、工作原理、复用原理及源码分析
深入理解Java并发编程之线程池、工作原理、复用原理及源码分析
210 0
|
人工智能 自然语言处理 UED
AI是在帮助创意人还是取代他们?
**摘要:** 随着AIGC技术的崛起,AI在创意设计领域的作用日益增强,从内容生成到复杂设计,如动画制作。尽管AI提高了效率,但它在情感表达和文化理解上仍无法替代人类设计师。Adobe国际认证成为设计师适应AI时代、提升竞争力的途径,鼓励设计师学习AI基础知识,掌握设计工具,并保持创造性思维。设计师应将AI视为合作伙伴,利用其优势提升工作效率,同时保持自身艺术价值和创新能力。
|
存储 缓存
uniapp存值和取值方法
uniapp存值和取值方法
426 0
|
机器学习/深度学习 计算机视觉 Python
【Python计算机视觉】项目实战之图像增强imguag对关键点变换、标注框变化(附源码 超详细必看)
【Python计算机视觉】项目实战之图像增强imguag对关键点变换、标注框变化(附源码 超详细必看)
385 0
|
小程序 前端开发 Java
微信小程序点餐系统的开发与实现
微信小程序点餐系统的开发与实现
541 0