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. File对象的常用方法

    File对象不仅可以表示文件,还可以表示目录,源码注释是这么说的:An abstract representation of file and directory pathnames. File类最常 ...

  2. jQuery 3D canvas 旋转木马(跑马灯)效果插件 - cloud carousel

    插件名称-cloud carousel 最新版本-1.0.5 支持ie6-ie9,firefox,chrome,opera,safari等 1.引入jquery1.4.2.js 和CloudCarou ...

  3. (转载)#include机制,#ifndef...#define...#endif防止重复引用,声明,定义等概念

    一.来自百度知道的问题:全局变量可以声明定义在头文件中? 答案: 注意头文件中不可以放变量的定义!!!一般情况下头文件中只放变量的声明,因为头文件要被其他文件包含(即#include).如果把定义放到 ...

  4. windows API实现用户选择文件路径的对话框

    在编写应用程序时,有时需要用户选择某个文件,以供应用程序使用,比如在某些管理程序中需要打开某一个进程,这个时候需要弹出一个对话框来将文件路径以树形图的形式表示出来,以图形化的方式供用户选择文件路径,而 ...

  5. MarkDown初遇

    MarkDown初遇 纠结盘桓许久,由于那只胖纸,最终决定再次捡起博客这个东东,记录记录生活中.心灵里的点点滴滴. 寻觅的过程中忽然发现MarkDown这个东东,查了查,学习成本不高,简洁而标准,关键 ...

  6. 分布式版本控制系统Git-----6.Git 常见命令一览表

    说明/备注 命令 备注 保存更新 git add [-i] -i 逐个确认 检查更新 git status 提交更新 git commit [-a] -m "<更新说明>&quo ...

  7. Django 1.8 - “No migrations to apply” when run migrate after makemigrations 解决办法

    解决办法 1 删除应用migrations目录 2 删除MySQL中django_migrations中对应的行(delete from django_migrations where app='ap ...

  8. mysql允许远程连接授权方法

    mysql数据库和apache不在同一台服务器时,需要远程连接mysql,这就要对mysql进行远程连接授权,为了安全只允许某些ip可以连接: 假如你想root用户从ip 192.168.2.12连接 ...

  9. JObject对json的操作

    一,需去程序集添加using Newtonsoft.Json.Linq;引用 using System; using System.Collections.Generic; using System. ...

  10. CascadeType

    当Hibernate配置了(JPA注解) cascade = { CascadeType.PERSIST, CascadeType.MERGE } 调用保存时 session.save(user); ...