Hero HDU4310 贪心
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.
InputThe 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)OutputOutput one line for each test, indicates the minimum HP loss.Sample Input
- 1
- 10 2
- 2
- 100 1
- 1 100
Sample Output
- 20
- 201
- #include<cstdio>
- #include<algorithm>
- #include<cmath>
- #include<vector>
- #include<queue>
- #include<cstring>
- #include<iostream>
- #define MAXN 25
- #define INF 0x3f3f3f3f
- #define eps 1e-11 + 1e-12/2
- typedef long long LL;
- using namespace std;
- /*
- 推公式
- A的伤害<B的伤害 即
- BD*AH <AD*BH
- */
- struct node
- {
- int d, h;
- };
- node a[MAXN];
- bool cmp(node l, node r)
- {
- return r.d*l.h < r.h*l.d;
- }
- int main()
- {
- int n;
- while (scanf("%d", &n) != EOF)
- {
- for (int i = ; i < n; i++)
- scanf("%d%d", &a[i].d, &a[i].h);
- sort(a, a + n, cmp);
- int time = , sum = ;
- for (int i = ; i < n; i++)
- {
- time += a[i].h;
- sum += (a[i].d)*time;
- }
- printf("%d\n", sum);
- }
- }
Hero HDU4310 贪心的更多相关文章
- hdu4310 贪心
考虑每次血口的要少 就按照一滴血多少伤害来计算.由于直接相除有小数.考虑x/y > a/b => x*b >y*a; #include<stdio.h> #inclu ...
- HDU-4310 Hero 贪心问题
题目链接:https://cn.vjudge.net/problem/HDU-4310 题意 打dota,队友太菜,局势变成1vN.还好你开了挂,hp无限大(攻击却只有一点每秒-_-). 但是你并不想 ...
- hdu4310 - Hero - 简单的贪心
2017-08-26 15:25:22 writer:pprp 题意描述: • 1 VS n对战,回合制(你打他们一下,需要受到他们所有存活人的攻击)• 你的血量无上限,攻击力为1• 对手血量及攻击 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- 暑假集训(2)第八弹 ----- Hero(hdu4310)
K - Hero Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:65536KB 64bit ...
- HDU4310:Hero
Problem Description When playing DotA with god-like rivals and pig-like team members, you have to fa ...
- HDU 4310 Hero (贪心)
题意:给定你有 n 个敌人,你的伤害是 1,给出每个敌人的伤害,和敌人的血量,每一回合你可以攻击一个敌人,并且所有敌人都会攻击你,除非它已经死了,问你最少要多少要消耗多少血量. 析:一个很明显的贪心问 ...
- 2016HUAS暑假集训训练2 K - Hero
题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/K 这也是一道贪心题,刚开始写时以为只要对每一敌人的攻击和血的乘积进行从小到大排序即 ...
- 2016HUAS_ACM暑假集训2K - Hero(英雄)
这也属于一个贪心题.关键是排序的依据. 这题排序的依据是敌人的伤害/血量(DPS/HP),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...
随机推荐
- set && muliset
#include <set> #include <iostream> #include <cstdio> #include <cctype> using ...
- 拦截机制中Aspect、ControllerAdvice、Interceptor、Fliter之间的区别详解
Spring中的拦截机制,如果出现异常的话,异常的顺序是从里面到外面一步一步的进行处理,如果到了最外层都没有进行处理的话,就会由tomcat容器抛出异常. 1.过滤器:Filter :可以获得Http ...
- Joseph UVA 1452 Jump
题目传送门 /* 数学:约瑟夫环问题的变形,首先定义f[i]表示剩下i个人时,最后一个选出的人,有个公式:f[i] = (f[i-1] + m) % i f[1] = 0(编号从0开始),那么类似最后 ...
- 用 NPOI 组件实现数据导出
利用 Nuget 安装 NPOI 组件. 所需引用的 dll:ICSharpCode.SharpZipLib.dll.NPOI.dll.NPOI.OOXML.dll.NPOI.OpenXml4Net. ...
- Python 模拟postman上传文件
最近工作需求:写的程序要用到python模拟postman操作,基于flask框架 代码很简单 但是百度一半天: import requests files = {'skFile': open(r&q ...
- EditPlus里面自带有更改文件编码的功能
- Microsoft SQL Server学习(六)--查询语句
联合查询 use student --建表 create table class_A( id int primary key, name varchar(50), sex char(50), cour ...
- PHP——基本使用(一)
Apache安装与配置 install 下载地址:https://www.apachelounge.com/download/,选择2.4.33版本64位 将程序解压到一个英文目录下,以管理身份打开c ...
- HDU_1505_矩阵中的最大矩形_dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 City Game Time Limit: 2000/1000 MS (Java/Others) ...
- day15-模块的基础及导入
目录 模块 什么是模块 使用模块 import 循环导入问题 解决方案一 解决方案二 模块的搜索路径 Python文件的两种用途 包 导入包内包 导入包内包的模块 绝对导入与相对导入 绝对导入 相对导 ...