Problem 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
 
//英语是硬伤。。。要不是看了别人的题解,我真心不知道原来输入时浮点型呀!!!
//这道题直接给我弄迷糊了。。。
//血量少攻击高的要先消灭,即将所有的敌人根据DPS/HP从大到小排序,如果相等,则按HP从小到大排序。
 
#include <iostream>
#include <algorithm> using namespace std; struct node
{
double hp;
double dps;
double bi;
} data[]; bool cmp(const node &a,const node &b)
{
if(a.bi>b.bi)
return true;
else if(a.bi==b.bi)
{
if(a.dps<b.dps)
return true;
else return false;
}
else return false;
} int main()
{
int n;
double ans;
while(cin>>n)
{
ans=;
for(int i=;i<n;i++)
{
cin>>data[i].hp>>data[i].dps;
data[i].bi=data[i].dps/data[i].hp*1.0;
}
sort(data,data+n,cmp);
for(int i=;i<n;i++)
{
while(data[i].hp)
{
for(int j=i;j<n;j++)
ans+=data[j].dps;
data[i].hp--;
}
}
cout<<ans<<endl;
}
return ;
}
 

HDU4310:Hero的更多相关文章

  1. BZOJ3864 & HDU4899:Hero meet devil——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3864 http://acm.hdu.edu.cn/showproblem.php?pid=4899 ...

  2. 2020网鼎杯 白虎组reverse:hero

    主函数,当bossexist的值不为0时,while循环dround()函数,循环结束输出flag outflag()函数的flag值由6段数据拼凑而成 while循环的dround()函数有三个选择 ...

  3. Cocos2dx游戏开发系列笔记13:一个横版拳击游戏Demo完结篇

    懒骨头(http://blog.csdn.net/iamlazybone QQ:124774397 ) 写下这些东西的同时 旁边放了两部电影 周星驰的<还魂夜> 甄子丹的<特殊身份& ...

  4. switch语句:适用于一个条件有多个分支的情况---分支语句

    例1: 客服选择功能,然后按按键 Console.WriteLine("查花费请按1,查余额请按2,查流量请按3,办理业务请按4,宽带请按5,人工服务请按6,集团业务请按7"); ...

  5. Angular 2.0 基础:服务

    什么是服务(Service) 在Angular 2 中我们提到的服务 service 一般指的是 哪些能够被其他组件或者指令调用的 单一的,可共享的 代码块.当然,通过服务可以将数据和组件分开,这样就 ...

  6. BZOJ5336:[TJOI2018]游园会——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5336 https://www.luogu.org/problemnew/show/P4590 小豆 ...

  7. python27期day13:闭包、装饰器初始、标准版装饰器、作业题

    1.闭包: 保护数据安全.保护数据干净性. 2.闭包的定义:在嵌套函数内.使用非全局变量(且不使用本层变量) 将嵌套函数返回 闭包的目的:要接受被装饰的函数和被装饰函数需要的参数3.闭包举例子: de ...

  8. [开发ing] Unity项目 - Hero英雄

    目录 游戏原型 项目演示 绘图资源 代码实现 技术探讨 参考来源 游戏原型 游戏介绍:这是一款横版类魂游戏,玩家将操控Hero,在诸神黄昏的墓地中,挑战源源不断的敌人,以及近乎无敌的强大boss 灵感 ...

  9. Django(五)1 - 4章实战:从数据库读取图书列表并渲染出来、通过url传参urls.py path,re_path通过url传参设置、模板语法

    一.从数据库读取图书数据并渲染出来 1)app1/views.py函数books编写 [1]从模型下导入bookinfo信息 [2]从数据库获取图书对象列表 [3]把获取到的图书对象赋值给books键 ...

随机推荐

  1. mac版tomcat修改端口无法访问,80端口无法访问

    在mac上安装好了tomcat,修改了端口为80,没想到关闭tomcat时提示出错,而且无法访问,原来我犯了两个错误. 1.我用的是mac上的文本编辑.app打开然后修改的,重新修改为8080也不行, ...

  2. javascript history对象

    window.history.[属性|方法] 0.history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能. 1.属性 2.方法

  3. jquery实现图片漂浮效果

    $(window).load(function(){   function moveRocket(){   $("#float").animate({'left':'+=100'} ...

  4. 奇葩json结构解析--key是数字的json处理

    json结构如下: { "ret": "ok", "data": { "57230": { "cat_id&q ...

  5. USACO 2.3 Cow Pedigrees

    Cow Pedigrees Silviu Ganceanu -- 2003 Farmer John is considering purchasing a new herd of cows. In t ...

  6. scala 数组 基本类型

    变量尽量用valvar 是不可变 final 常用的 Int̵ Double̵ Long̵ String没有基本类型.scala 任何对象都继承Any Int Double 继承AnyVal Stri ...

  7. c# 使用 HttpWebRequest模拟登陆

    c# 使用 HttpWebRequest模拟登陆(附带验证码) 分类: C# .net2010-06-04 00:50 35647人阅读 评论(43) 收藏 举报 c#exceptionstreams ...

  8. 《JS权威指南学习总结--7.9 ES5中的数组方法》

    内容要点: ES5中定义了9个新的数组方法来遍历.映射.过滤.检测.简化和搜索数组. 概述:首先,大多数方法的第一个参数接收一个函数,并且对数组的每个元素(或一个元素)调用一次该函数. 如果是稀疏数组 ...

  9. 明天学习一下验证码的匹配和thinkphp第十三章

    333333333 js 冒泡排序 var arr=[17,19,5,90,3];window.onload=function(){// alert(arr[0]);var len=arr.lengt ...

  10. Node.js:服务器与数据流

    1.Node 常被用来构建服务器,下面代码就是创建了一个服务器. var http = require('http'); var server = http.createServer(); serve ...