HDU-4310-HERO

news/2025/1/12 21:54:32/

原题:
When playing DotA with god-like rivals and pig-like team members, you have to face an embarrassing situation: All your teammates are killed, and you have to fight 1vN.

There are two key attributes for the heroes in the game, health point (HP) and damage per shot (DPS). Your hero has almost infinite HP, but only 1 DPS.

To simplify the problem, we assume the game is turn-based, but not real-time. In each round, you can choose one enemy hero to attack, and his HP will decrease by 1. While at the same time, all the lived enemy heroes will attack you, and your HP will decrease by the sum of their DPS. If one hero’s HP fall equal to (or below) zero, he will die after this round, and cannot attack you in the following rounds.

Although your hero is undefeated, you want to choose best strategy to kill all the enemy heroes with minimum HP loss.
Input
The first line of each test case contains the number of enemy heroes N (1 <= N <= 20). Then N lines followed, each contains two integers DPSi and HPi, which are the DPS and HP for each hero. (1 <= DPSi, HPi <= 1000)
Output
Output one line for each test, indicates the minimum HP loss.
Sample Input
1
10 2
2
100 1
1 100
Sample Output
20
201
题意:
你有n个敌人,每个人都有自己的攻击力d和生命值h,你每回合可以减少其中任何一个人的h 1点,当敌人的h<=0时死亡。但你每回合都要受到所有人的攻击,求你最少掉多少血。
题解:
根据计算可以把两个人之间的h1d2与h2d1进行比较,大的作为先攻击的对象。
计算过程:
不再赘述,读者可以在稿纸上列举两个例子t1和t2,分别计算先攻击t1和先攻击t2,中间所受伤害的差值,计算可以得出以上结论。
附上AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct enemy
{int d;//伤害值int h;//生命值
}a[25];
bool cmp(enemy a,enemy b)//以d.h作为关键值比较
{int c,d;c=a.h*b.d;d=a.d*b.h;return c<d;
}
int main()
{int n,k,z;while(scanf("%d",&n)!=EOF){memset(a,0,25*sizeof(enemy));//初始化k=0;z=0;for(int i=0;i<n;++i){scanf("%d%d",&a[i].d,&a[i].h);z+=a[i].d;//计算最开始时的总伤害量}sort(a,a+n,cmp);for(int i=0;i<n;i++){k+=z*a[i].h;//计算伤害和z-=a[i].d;}printf("%d\n",k);}return 0;
}

以前写过的题,补发一下blog。
欢迎评论!


http://www.ppmy.cn/news/488816.html

相关文章

hdu 4310 Hero

hdu 4310 Hero 题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid4310 贪心水 题目大意&#xff1a;以DotA为背景&#xff0c;英雄PK一对多&#xff0c;我方英雄不死&#xff0c;问杀死敌方所有英雄的时候&#xff0c;我方min英雄战损&…

CVE-2021-4034:Linux Polkit 权限提升漏洞复现及修复

CVE-2021-4034&#xff1a;Linux Polkit 权限提升漏洞复现及修复 本文仅为验证漏洞&#xff0c;在本地环境测试验证&#xff0c;无其它目的 CVE 编号&#xff1a; CVE-2021-4034 漏洞说明&#xff1a; 近期&#xff0c;国外安全研究团队在 polkit 的 pkexec 中发现存在的本地…

AR9344

MW4530R 750M FW4530r &#xffe5;60 tp 2041n, tl-wdr4320有USB接口 TP-LINK 941v6 &#xffe5;70 2041v1 2.4G WDR 4310 WDR4320 WDR3500 WDR3600 水星 MW4530R MW3030R 水星mw4530r&#xff0c;考虑和tp4310配置基本相同 附上4530r的配置&#xff0c;其实和4310几乎一样…

STLloader预览服务端stl文件

最近写项目的时候遇到了一个问题 就是我使用STLloader时 loader.load("服务端地址"&#xff0c;function) 会报csp错误 Content Security Policy: 页面设置阻止读取位于 blob:http://localhost:8080/06f90dbb-6fa5-4310-aad0-7a85b227f479 的一项资源("connec…

Linux: 获取硬盘的UUID信息

简介 UUID&#xff08;英语&#xff1a;Universally Unique Identifier&#xff0c;通用唯一识别码&#xff09;&#xff0c;是用于计算机体系中以识别信息数目的一个128位标识符。UUID可以用来标识与安装点(mount point)或名称无关对设备。现在许多设备都支持热插拔(hot-plug…

Texlive安装失败(报错“check_file_and_remove failed”)解决方案

问题描述 通过tex提供的安装程序install-tl-windows.exe 和Tex官方下载链接下载安装texlive出现异常&#xff1a; ……省略之前的安装日志…… Installing [4307/4310, time/total: 09:58:44/09:59:32]: zxjafbfont [3k] Installing [4308/4310, time/total: 09:58:50/09:59:3…

TI - MCU - MSP430使用指南1 - MSP430简介及选型指南

前言&#xff1a;很幸运能够进入半导体这个充满未来和机遇的行业&#xff0c;同时深刻接触到TI公司MCU产品MSP430&#xff0c;接下来我会用一系列的文章来描述MSP430产品性能、优势、资料及使用方法。 首先先介绍一下TI公司&#xff0c;一个集高科技与创新于一体的企业&#x…

服务器 Unbuntu重启后,nvidia-smi 不能使用

问题 用来深度学习的服务器重启了&#xff0c;结果会导致nvidia-smi 失效&#xff0c;会出现这样的错误&#xff1a; NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver.原因 Ubuntu 重启后会升级内核&#xff0c;升级后的内核与之前 的nvidi…