题目连接: Fight with Monsters

题目:

There are n monsters standing in a row numbered from 1 to n. The i-th monster has hi health points (hp). You have your attack power equal to a hp and your opponent has his attack power equal to b hp.

You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to 0.

The fight with a monster happens in turns.

You hit the monster by a hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.
Your opponent hits the monster by b hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster.
You have some secret technique to force your opponent to skip his turn. You can use this technique at most k times in total (for example, if there are two monsters and k=4, then you can use the technique 2 times on the first monster and 1 time on the second monster, but not 2 times on the first monster and 3 times on the second monster).

Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

Input
The first line of the input contains four integers n,a,b and k (1≤n≤2⋅105,1≤a,b,k≤109) — the number of monsters, your attack power, the opponent’s attack power and the number of times you can use the secret technique.
The second line of the input contains n integers h1,h2,…,hn (1≤hi≤109), where hi is the health points of the i-th monster.

Output
Print one integer — the maximum number of points you can gain if you use the secret technique optimally.

Examples
Input

6 2 3 3
7 10 50 12 1 8
Output
5

Input
1 1 100 99
100
Output
1

Input
7 4 2 1
1 3 5 4 2 7 6
Output
6

大致题意:

简单来说, 就是有A, B两个人打怪兽(A是主角), A的攻击力为a, B的攻击力为b, 如果A给予怪兽最后一击, 则加一分, 如果B给予怪兽最后一击, 则不得分. 但是因为A是主角, 他可以开挂, 效果就是可以让B不攻击一轮, 但是只能用k次. 问你最多能得多少分.

解题思路:

这个题, 有些怪物的血量刚好A打一下B打一下, 最后A打死, 不用开挂 属于白给分数.
剩下的怪需要开挂能被A打死, 那就看看这个怪需要开挂多少次, 记录下来, 最后把所有开挂的次数sort一下, 取小即可.

AC代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int cou[1000000]; //记录打死这个怪需要开挂的次数.
int main(void)
{int n, a, b, k, h; int res = 0; //初始得分0cin >> n >> a >> b >> k;for (int i = 1; i <= n; i++) {scanf("%d", &h); //得到当前怪物血量if (h % (a + b) <= a && h % (a + b) > 0) res++; //属于白给类型, 注意判断>0的部分, 如果=0说明刚好被B打死, 得开挂else {h = h % (a + b); //打完了整数轮后怪物剩的血量, 应该是>a的if (h == 0)  h = a + b; //特殊情况, 如果B刚好打死怪物, 我们滚回一轮, 假设这轮没打cou[i] = h % a ? h / a + 1 : h / a; cou[i]--; //看看A需要打多少次打死这个怪物, 需要开挂的次数要-1,//因为最后一次A直接把怪物打死 不用开挂}}sort(cou + 1, cou + 1 + n); //排序for (int i = 1; i <= n; i++) {if (cou[i] && k - cou[i] >= 0) k -= cou[i], res++;}cout << res << endl;return 0;
}

这个题还是很水的. 没啥可说的 单独记录一下, 因为最近遇到的打怪题还挺多的. 有许多的题人还有血, 怪还会回血, 有许多涉及到思路优化的地方. 我发现这些进行回合轮次战的题目, %的运用是否得当是解题的关键.

END

Fight with Monsters相关推荐

  1. CodeForces - 1296D Fight with Monsters

    一.内容 There are n monsters standing in a row numbered from 1 to n. The i-th monster has hi health poi ...

  2. 【2018icpc宁夏邀请赛现场赛】【Gym - 102222H】Fight Against Monsters(贪心排序)

    题干: It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagna ...

  3. H. Fight Against Monsters

    题目链接 贪心求解,a.atk/a.time值较大的排在前边.但是这样使用除法会导致精度损失,compare函数中的比较规则变为a.atk*b.time>b.atk*a.time就行了.当相等的 ...

  4. Codeforces 1296D Fight with Monsters

    有n 只怪兽,第i只怪兽的血量为 h[i] ,你的攻击力为 a ,你的对手攻击力为 b.注意,打每一只怪兽都是由你先开始攻击一次,再由你的对手攻击一次,轮流攻击.若怪兽最后由你打死得1分,对手打死你不 ...

  5. topcoder-SRM565-div2-第二题-500分--搜索/动态规划

    不想看英文的题目?翻译在后面 Problem Statement      Manao is traversing a valley inhabited by monsters. During his ...

  6. 怎么赚美金_我16岁时如何赚到200,000美元

    怎么赚美金 by RJ 由RJ About three years ago, I published a story about how the Twitter app I built in high ...

  7. (Java小游戏)魔塔v1.0

    实现一个控制台操作的4399小游戏--魔塔 游戏情景如下: 勇士类 怪物类 怪物数组类 地图类 游戏类测试类 测试类 代码如下 勇士类Hero.java package com.nll.oop1; / ...

  8. shadow fight 1.6.0 内购

    shadow fight 之前的版本只需要安装LocallApstore即可内购. 1.6.0的版本中加了越狱检查. 所以LocallApstore 无法直接使用. 需要安装xcon避开越狱检查. 也 ...

  9. 2016级算法期末上机-F.中等·AlvinZH's Fight with DDLs II

    1118 AlvinZH's Fight with DDLs II 思路 中等题,贪心. 理解题意,每次攻击中,可以使某个敌人生命值-1,自己生命值减去∑存活敌人总攻击力. 贪心思想,血量少攻击高的要 ...

最新文章

  1. apache mysql php实现最大负载的方法_如何架设高性能nginx+php+mysql搭配的服务器,解决高并发问题...
  2. 阿里开源富容器引擎 PouchContainer 的 network 连接机制
  3. html中传递sessionid,sessionID是怎么在客户端和服务器端传递的?
  4. JSON学习笔记(五)- JSON.stringify()
  5. Spring Hibernate教程
  6. 设计java application程序_下面哪些步骤是Java Application程序的建立及运行的步骤( )...
  7. 【java】java 分支预测 Java处理排序后的数组比没有排序的快
  8. srsLTE源码学习:网络附属存储抓包nas_pcap.h
  9. ArcEngine中shp中先加入要素然后删除一部分要素后,放大图形后不显示的问题解决方法...
  10. LeetCode 104.二叉树的最大深度(递归)
  11. .net知识和学习方法系列(二十五) .net中的windows service与服务操作
  12. appium使用教程python_appium使用教程(一 环境搭建)-------------2.安装部署
  13. 二分类变量相关性分析spss_两个有序分类变量相关性的卡方检验-SPSS教程
  14. 如何修改电脑微信的提示音(亲测有效)
  15. Maven的基本使用操作
  16. 高薪职位不少,这个行业为什么如此缺人才?
  17. office2003和office2007及office2010共存的方法
  18. 硬件设计之一——电源设计05:过电流能力
  19. VBScript UBound 函数
  20. Ubuntu 16.04 系统 gflags glog 安装

热门文章

  1. 恶搞房价版《越光宝盒》
  2. centos安装Java环境和oracle数据库
  3. 【零基础学Java】第九天 IDEA的免费使用和常用设置及快捷键
  4. 学而时习之(1):单边sar adc测热电偶温度
  5. framework/netcore 任务调度 FluentScheduler
  6. JS导航栏子节点练习,onmouseover和onmouseout事件
  7. 12月值得一看的10款P2E游戏
  8. java 执行ddl语句_在JDBC中,如何知道DDL语句是否成功执行?
  9. 日期和时间戳转换方式
  10. 进化算法之粒子群算法和Matlab实现(多维)