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),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...
随机推荐
- Androidstudio的安装与使用调试
1安装与基本使用 1.1androidstudio的安装 1.到android-studio\bin文件夹里面,根据自己的电脑配置,打开studio.exe或者studio64.exe 2.按照向导默 ...
- MyEclipse无法自动编译项目故障一例
MyEclipse导入项目后发现无法自动编译,classes目录下没有编译的类. 尝试的解决方法: 1.刷新项目,失败: 2.project->clean-,失败: 3.关闭项目再次打开,失败: ...
- 最简单的SPA(单页应用)实现
$(function(){ var replacePage = function(href, onFinish){ $.get(href,{},function(raw){ var data = ra ...
- [转]我要学ASP.NET MVC 3.0(十二): MVC 3.0 使用自定义的Html控件
本文转自:http://www.cnblogs.com/lukun/archive/2011/08/05/2128693.html 概述 在ASP.NET MVC框架中已经封装了很多基于Html标 ...
- React组件的防呆机制(propTypes)
Prop验证 随着应用不断变大,为了保证组件被正确使用变得越来越重要.为此我们引入propsTypes.React.PropTypes提供很多验证器(valodator)来验证传入的数据的有效性.当向 ...
- PAT 甲级1135. Is It A Red-Black Tree (30)
链接:1135. Is It A Red-Black Tree (30) 红黑树的性质: (1) Every node is either red or black. (2) The root is ...
- js正则表达式限制文本框只能输入数字,小数点,英文字母
1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafter ...
- 更新html技术比较
document.write() document对象的write方法可以很简单的向页面的源代码中添加内容,不过不推荐使用. 优点:可以快速简单的让初学者理解如何向页面添加内容: 缺点: 只有页面初始 ...
- 安装mask-rcnn问题汇总
1. I download file from https://github.com/waleedka/coco. Then I placed the file in Mask_RCNN-master ...
- Crash reporter
A crash reporter is a software application whose function is to identify report crash details and to ...