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 ...
随机推荐
- 【常见浏览器的UA】
"所谓 UA(User Agent / 用户代理),最初是指浏览器告知网站管理员,本浏览器支持的类型和框架,让网站管理员以支持的模式结构向浏览器发送页面,呈现给用户浏览.演变到今天,网站管理 ...
- argparse 模块使用
import argparse,os data_func=["upload","download"]req_func=["getfunc", ...
- ClickOnce部署,修改deploymentProvider
打开 以.application 为后缀的文件,找到并修改 <deploymentProvider codebase="" /> 即可
- Jmeter变量嵌套的方法
jmeter中变量的嵌套一般有两种方式 1,调用__V函数 { "phone": "${phone}", "xxId": "${_ ...
- C/C++ 传递信息给Java
#开始 今天有人问我C++怎么给Java传递消息 大概需求是 用C++写了一个窗口 需要把编辑框里面的东西传递给Java做处理 #解决过程 我现在能想到的有三个简单的方法 1. Socket编程 通过 ...
- watch监听变化
<template> <div> 父级 <childCom1 @click.native="fn()"></childCom1> { ...
- 炸鱼w咕咕咕
退役选手又回来了w + 将近一个月莫有学OI变得十分笨拙 + 洛谷打卡从300+ 变为 10 + 冬令营加油(虽然我会崩 + 省选加油 (虽然我进不去
- linux +jenkins +python 集成测试
1.jenkin安装部署 2.git 安装 3.git server 配置 4.contab
- VMware15下载、安装、激活
1.VMware15下载 链接:https://pan.baidu.com/s/1bI8LReRY-5k81O3rrNgg-A 提取码:6c03 2.VMware15安装 3.VMware15激活
- ASP.NET FileUpload 上传文件类型验证
验证的核心方法: public static bool IsAllowedExtension(FileUpload hifile) { //原方法是这样的,会提示找不到文件 //System.IO.F ...