Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

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个人,然后输出最后你受到的伤害,最划算的方法不是先打攻击力高的,也不是血量少的,而是攻击力与血量比值最高的。嘛,也就是传说中中的性价比啦~
那就按性价比从高到低排序吧~
注意的地方是你在攻击他人的时,其余人也会对你造成伤害哦!也就是说在你打败一个人之前,你受到的伤害都是所有人的总攻击力啦,直到你把一个人打败才能改变,也就是说从开始,到打败一个人所受伤害即是被击败者的血量乘以初始所有人的总攻击力,然后减去被打败者的攻击力,继续循环下去....
代码如下:
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std; struct Enemy
{
int hp;
int dps;
}enemy[]; bool cmp(const Enemy &a,const Enemy &b)
{
return (double)a.dps/(double)a.hp>(double)b.dps/(double)b.hp;
} int main()
{ int n;
while(~scanf("%d",&n))
{ int myhp=;
int alldps=;
memset(enemy,,sizeof(enemy));
for (int i=;i<n;i++)
{
scanf("%d %d",&enemy[i].dps,&enemy[i].hp);
alldps+=enemy[i].dps;
}
sort(enemy,enemy+n,cmp);
for(int i=;i<n;i++)
{
myhp+=enemy[i].hp*alldps;
alldps-=enemy[i].dps;
}
printf("%d\n",myhp);
}
return ;
}

Hero的更多相关文章

  1. H5游戏开发之Stick Hero

    自从上次发布一个小恐龙游戏以后,到现在10天了,前后又写了3个游戏,挑了一个感觉比较有挑战的游戏和大家分享一下. 效果演示 这是我模拟一个苹果游戏<stick hero>游戏写的一个小游戏 ...

  2. BZOJ 1191 超级英雄 Hero 题解

    BZOJ 1191 超级英雄 Hero 题解 Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金 ...

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

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

  4. 【入门】匈牙利算法+HNOI2006 hero超级英雄

    一.关于匈牙利算法 匈牙利算法是由匈牙利数学家Edmonds提出的,用增广路径求二分图最大匹配的算法. 听起来高端,其实说白了就是: 假设不存在单相思(单身狗偷偷抹眼泪),在一个同性恋不合法的国家里( ...

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

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

  6. bzoj 1191: [HNOI2006]超级英雄Hero

    1191: [HNOI2006]超级英雄Hero Time Limit: 10 Sec  Memory Limit: 162 MB 二分图匹配... Description 现在电视台有一种节目叫做超 ...

  7. HDU 4901 The Romantic Hero

    The Romantic Hero Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u D ...

  8. HDU4901 The Romantic Hero 计数DP

    2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...

  9. HDU 4310 Hero (贪心算法)

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

  10. BZOJ 1191: [HNOI2006]超级英雄Hero 二分匹配

    1191: [HNOI2006]超级英雄Hero Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或 ...

随机推荐

  1. js如何解析后台传过来的json字符串

    1.js如何解析后台传过来的json字符串? 注意:js是无法直接接收和使用json或者Php的数据,用的话会出现undefined,所以要转换一下. 方式一: var str = '{"r ...

  2. MySQL日期数据类型总结

    MySQL:MySQL日期数据类型.MySQL时间类型使用总结 MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型        存储空间      日期格式           ...

  3. string基本字符系列容器(一)

    C++STL提供了string基本字符系列容器来处理字符串,可以把string理解成字符串类,它提供了添加,删除,替换,查找和比较等丰富的方法. 使用string容器,需要头文件包含声明#includ ...

  4. AntD02 Table组件的使用

    1 前提准备 1.1 创建一个angular项目 1.2 将 Ant Design 整合到 Angular 项目中 1.3 官方文档 点击前往 2 简单使用 <nz-table #rowSele ...

  5. python日期,时间函数

    获取当前格式化时间: now_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) 获取当前时间戳: now_tim ...

  6. javascript nonono

    javascript实现的点击元素实现当前轮换展现效果 javascript实现的点击元素实现当前轮换展现效果:本章节分享一段代码实例,它实现了点击元素实现当前展现效果,并且具有比较人性化的变换效果. ...

  7. Selenium家谱

    自动化测试一词也算是整个测试行业里面比较热门的一个词儿,工资高,前景好,有实力,有态度等等,很多企业的管理者也在不断的扩大自己的队伍和职能,这也是导致自动化测试比较流行的原因之一.但是很多企业做自动化 ...

  8. open与fopen的用法

    1.  fopen    打开普通文件 带缓冲区 缓冲文件系统是借助文件结构体指针来对文件进行管理,通过文件指针来对文件进行访问,既可以读写字符.字符串.格式化数据,也可以读写二进制数据.   函数原 ...

  9. POJ - 3984 迷宫问题 BFS求具体路径坐标

    迷宫问题 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...

  10. DELPHI XE5 跨平台 Form ShowModal 官方示例

    Calling ShowModal as an Anonymous Method on All Platforms procedure THeaderFooterForm.btnPickClick(S ...