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. C# 从零开始 vol.1

    说好的java只能先坑了,毕竟计划赶不上变化,以下是 c# 基础部分. 1:变量,方法的命名方式 目的就是一眼看到实例名 方法名 就知道该变量是做什么的. 主流的命名方式有驼峰命名规则,pascal命 ...

  2. ACE Socket Wrapper Facade

    ACE Socket Wrapper Facade 1:Socket API 1.1 IPC(进程间通信) IPC分为本地IPC(同一计算机上的不同进程)和远程IPC(网络互联的不同计算机),本地IP ...

  3. css3技巧属性之text-overflow

    text-overflow:clip | ellipsis 默认值:clip 取值: clip: 当对象内文本溢出时不显示省略标记(...),而是将溢出的部分裁切掉. ellipsis: 当对象内文本 ...

  4. Struts2第四天

    Struts2第四天 昨天: 自定义的拦截器:继续methodFilterInterceptor,可以指定哪些方法需要拦截或者不拦截. Intercepters(配置拦截器),intercepter( ...

  5. UVa 12100 Printer Queue (习题 5-7)

    传送门:https://uva.onlinejudge.org/external/121/12100.pdf 题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), ...

  6. 2016年团体程序设计天梯赛-决赛 L1-1. 正整数A+B(15)

    本题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000].稍微有点麻烦的是,输入并不保证是两个正整数. 输入格式: 输入在一行给出A和B,其间以空格分开.问题是A和B不一定是满 ...

  7. 一、链接Sql Server2014提示找不到实例的问题解决方案

    在登录数据库时,确认数据库地址.用户名.密码正确的情况下,却报如下错误,则说明目标数据库服务器有相应的服务未启动. 在目标数据库服务器中打开服务列表: 找到SQL Server(****)服务(括号中 ...

  8. shell脚本学习(三)

    1.在grep中, ^标记着单词的开始, $ 标记着单词的结束. 查看一个单词是否在linux自带的词典中,脚本如下: #bin/sh #文件名:checkword.sh word=$1 grep & ...

  9. Matlab - 矩阵元素引用

    >> A = [ ; ; ] A = 1. 选择第m行n列的元素 >> A(,) ans = 2. 选择第i列所有元素 >> A(:,) ans = 3. 选择第j ...

  10. digitalocean开通德国法兰克福机房,40Gb带宽,支持IPv6

    2015年4月15日,vps服务商digitalocean宣布正式开通德国法兰克福机房.5个月前digitalocean宣布筹备Germany机房中心,经过近1个月部署,总算与用户见面了.Frankf ...