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.

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 贪心的更多相关文章

  1. hdu4310 贪心

    考虑每次血口的要少 就按照一滴血多少伤害来计算.由于直接相除有小数.考虑x/y > a/b  =>  x*b >y*a; #include<stdio.h> #inclu ...

  2. HDU-4310 Hero 贪心问题

    题目链接:https://cn.vjudge.net/problem/HDU-4310 题意 打dota,队友太菜,局势变成1vN.还好你开了挂,hp无限大(攻击却只有一点每秒-_-). 但是你并不想 ...

  3. hdu4310 - Hero - 简单的贪心

    2017-08-26  15:25:22 writer:pprp 题意描述: • 1 VS n对战,回合制(你打他们一下,需要受到他们所有存活人的攻击)• 你的血量无上限,攻击力为1• 对手血量及攻击 ...

  4. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  5. 暑假集训(2)第八弹 ----- Hero(hdu4310)

    K - Hero Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     64bit ...

  6. HDU4310:Hero

    Problem Description When playing DotA with god-like rivals and pig-like team members, you have to fa ...

  7. HDU 4310 Hero (贪心)

    题意:给定你有 n 个敌人,你的伤害是 1,给出每个敌人的伤害,和敌人的血量,每一回合你可以攻击一个敌人,并且所有敌人都会攻击你,除非它已经死了,问你最少要多少要消耗多少血量. 析:一个很明显的贪心问 ...

  8. 2016HUAS暑假集训训练2 K - Hero

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/K 这也是一道贪心题,刚开始写时以为只要对每一敌人的攻击和血的乘积进行从小到大排序即 ...

  9. 2016HUAS_ACM暑假集训2K - Hero(英雄)

    这也属于一个贪心题.关键是排序的依据. 这题排序的依据是敌人的伤害/血量(DPS/HP),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...

随机推荐

  1. Js 使用小技巧总结(1)

    1.Js 的时间控制,小于初始时间,大于截止时间 <script type="text/javascript">        window.onload = Game ...

  2. Spark学习笔记1:Application,Driver,Job,Task,Stage理解

    看了spark的原始论文和相关资料,对spark中的一些经常用到的术语做了一些梳理,记录下. 1,Application application(应用)其实就是用spark-submit提交的程序.比 ...

  3. 论tab切换的几种实现方法

    tab切换在网页中很常见,故最近总结了4种实现方法. 首先,写出tab的框架,加上最简单的样式,代码如下: <!DOCTYPE html> <html> <head> ...

  4. Javascript的一些技巧(《Javascript DOM编程艺术》、Javascript语言精粹)

    1.什么时候用布尔变量当变量 假设你需要一个这样的变量:我在睡觉——存为一个值:我没在睡觉——存为另一个值. 一般的做法: var stateOne="睡觉",stateTwo=& ...

  5. LockDemo 锁对象

    class Resource { private boolean flag = false; private String name; private int count; //资源锁 Lock lo ...

  6. Anniversary Cake

    Anniversary Cake Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15704   Accepted: 5123 ...

  7. MFC_2.1使用单选和多选框

    使用单选和多选框 单选 1.拖控件 设置名字,CTRL+D设置顺序,属性设置第一个GROUP为TRUE: 2.设置第一个按钮绑定变量为 值 INT型 名称m_RadioIndxe; 3.设置单击响应内 ...

  8. WindowsForms获取服务名称

    StringBuilder sb = new StringBuilder(); ServiceController[] services = ServiceController.GetServices ...

  9. 扩增子统计绘图1箱线图:Alpha多样性

    绘制Alpha多样性线箱图 绘图和统计全部为R语言,建议复制代码,在Rstuido中运行,并设置工作目录为存储之前分析结果文件的result目录 # 运行前,请在Rstudio中菜单栏选择“Sessi ...

  10. 二叉查找树(Binary Search Tree)

    Date:2019-06-25 14:40:32 基本操作 注意:数据量较大时,插入建树的时间复杂度会很高,慎用! //查找 void Search(node *root, int x) { if(r ...