Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)
There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health points (hp). You have your attack power equal to aa hp and your opponent has his attack power equal to bb 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 00 .
The fight with a monster happens in turns.
- You hit the monster by aa 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 bb 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 kk times in total (for example, if there are two monsters and k=4k=4 , then you can use the technique 22 times on the first monster and 11 time on the second monster, but not 22 times on the first monster and 33 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.
The first line of the input contains four integers n,a,bn,a,b and kk (1≤n≤2⋅105,1≤a,b,k≤1091≤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 nn integers h1,h2,…,hnh1,h2,…,hn (1≤hi≤1091≤hi≤109 ), where hihi is the health points of the ii -th monster.
Print one integer — the maximum number of points you can gain if you use the secret technique optimally.
6 2 3 3
7 10 50 12 1 8
5
1 1 100 99
100
1
7 4 2 1
1 3 5 4 2 7 6
6
读入的时候进行预处理,先模一下a+b,如果变成0了的话+b,不为零的话-a。本质上都是看在不跳过的情况下,最后一轮里自己攻击后处于什么状况。然后对数组由小到大排序。这里有一个贪心的思想,因为在此之后都是要靠k次跳过对手的攻击,所以说怪物剩余血量越少对自己越有利,这样能尽可能用较少的跳过次数把怪KO。之后遍历数组统计分数,同时相应的减去跳过次数。
#include <bits/stdc++.h>
using namespace std;
int n,a,b,k;
int h[];
long long ans=;
int main()
{
cin>>n>>a>>b>>k;
int i;
for(i=;i<=n;i++)
{
scanf("%d",&h[i]);
h[i]%=(a+b);
if(h[i]==)h[i]+=b;
else h[i]-=a;
}
sort(h+,h+n+);
for(i=;i<=n;i++)
{
if(h[i]<=)
{
ans++;//血量小于0说明最后一轮自己能直接获得人头
continue;
}
else
{
if(h[i]-k*a<=)
{
ans++;
if(h[i]%a==)k-=h[i]/a;
else k-=(h[i]/a+);
}
else
{
continue;
}
}
}
cout<<ans<<endl; return ;
}
Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)的更多相关文章
- Codeforces Round #617 (Div. 3) D. Fight with Monsters
D : Fight with Monsters 题目大意 : 有一组数,每个值对应着一个怪物的 hp 值,现在有两个人,一个自己一个对手,每个人有一个攻击值, 两个人轮流攻击怪物,如果是自己将怪物先打 ...
- Codeforces - 102222H - Fight Against Monsters - 贪心
https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1 ...
- Codeforces #617 (Div. 3) C. Yet Another Walking Robot
There is a robot on a coordinate plane. Initially, the robot is located at the point (0,0)(0,0) . It ...
- Codeforces #617 (Div. 3)B. Food Buying
Mishka wants to buy some food in the nearby shop. Initially, he has ss burles on his card. Mishka ca ...
- Codeforces 631 (Div. 2) E. Drazil Likes Heap 贪心
https://codeforces.com/contest/1330/problem/E 有一个高度为h的大顶堆:有2h -1个不同的正整数,下标从1到2h−1,1<i<2h, a[i] ...
- Codeforces #366 (Div. 2) D. Ant Man (贪心)
https://blog.csdn.net/liangzhaoyang1/article/details/52215276 原博客 原来好像是个dp题,不过我看了别人的博客使用贪心做的 复杂度(n^ ...
- Codeforces Round #617 (Div. 3) 补题记录
1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...
- Codeforces Round #617 (Div. 3) 题解
又是隔了一年才来补题的我 A.B水题就不用说了 C - Yet Another Walking Robot C题我居然卡了一会,最后决定用map水,结果出来看了看题解,居然真的是map...没想到会出 ...
- [CF百场计划]Codeforces Round #617 (Div. 3)
A. Array with Odd Sum Description You are given an array \(a\) consisting of \(n\) integers. In one ...
随机推荐
- Codeforces Round #614 (Div. 2)E(思维,构造,DP)
构造边权,从0开始给边赋值,初始选取一条边权为0,每次赋值的贡献为这一条链两侧的结点(包含链的端点)个数之积,下一次赋值以当前链其一端点续一条边,边权为上次赋的值+1.先DFS找到点的组合这条链两侧结 ...
- 压缩/批量压缩/合并js文件
写在前面 如果文件少的话,直接去网站转化一下就行. http://tool.oschina.net/jscompress?type=3 1.压缩单个js文件 cnpm install uglify-j ...
- 【Python】爬虫原理
前言 简单来说互联网是由一个个站点和网络设备组成的大网,我们通过浏览器访问站点,站点把HTML.JS.CSS代码返回给浏览器,这些代码经过浏览器解析.渲染,将丰富多彩的网页呈现我们眼前: 一.爬虫是什 ...
- aarch64环境下,搭建并配置服务器tomcat:
aarch64环境下,搭建并配置服务器tomcat: 环境说明及下载相关文件: 1. ARM环境:aarch64开发板 2.JDK安装包: jdk-8u231-linux-arm64-vfp-hflt ...
- 本次我们使用idea构建springmvc项目
该案例的github地址:https://github.com/zhouyanger/demo/tree/master/springmvcdemo1 1.首先我们可以创建maven项目,file-&g ...
- Springmvc-crud-02错误(添加出现中文乱码)
错误: 在进行添加页面时使用post请求,输入中文时会出现乱码 原因: post请求不支持gbk格式,使用字符编码过滤器,设置为UTF-8编码即可 注意配置请求的字符集和响应字符集 解决方案:需要放在 ...
- flask使用websocket
# flask使用websocket 1.概述 flask实现websocket有两种方式:flask_sockets,Flask-SocketIO. flask_sockets:该方式是flask对 ...
- 入门chrome插件开发教程和经验总结,一篇就搞掂!
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_44244857/articl ...
- Python基础数据类型以及对应方法
数据类型 不可变数据(四个):Number(数字).String(字符串).Tuple(元组).Sets(集合):可哈希 可变数据(两个):List(列表).Dictionary(字典).不可哈希 字 ...
- 《TCP/IP网络编程》读书笔记
1.Windows 下的 socket 程序和 Linux 思路相同,但细节有所差别(1) Windows 下的 socket 程序依赖 Winsock.dll 或 ws2_32.dll,必须提前加载 ...