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 ;
}

最新文章

  1. PL/Cool
  2. 【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
  3. CoreLocation框架的使用---地理编码
  4. [IR] Boolean retrieval
  5. 关于html5不支持frameset的解决方法
  6. c++builder6.0 mdi窗体+自定义子窗体
  7. BeanFactory与FactoryBean
  8. 【BZOJ】1925: [Sdoi2010]地精部落 DP+滚动数组
  9. Linux学习笔记19——信号2
  10. [转]让程序在崩溃时体面的退出之SEH
  11. Catel帮助手册-Catel.Core:(1)参数检查
  12. ZOJ3640-Help Me Escape
  13. MySQL——修改一个表的自增值
  14. 【LeetCode191】Number of 1 Bits★
  15. 【Visual Studio】VS发布应用未能创建默认证书的问题解决方法
  16. windows下,将MySQL做成服务/脚本启动
  17. maven 添加jdbc6
  18. LPC-LINK 2 Board IO
  19. VC/MFC程序开启关闭和打开自己或其他软件,更改窗口类
  20. 【Python】错误、调试和测试

热门文章

  1. 值得一做》关于并查集的进化题目 BZOJ1015(BZOJ第一页计划)(normal-)
  2. yii2 源码分析1从入口开始
  3. solidity错误处理
  4. Shiro——概述
  5. hdu 1905 Pseudoprime numbers
  6. What is difference between 3-layer architecture and MVC architecture?
  7. (转)Asp.Net生命周期系列一
  8. 编写高质量代码改善C#程序的157个建议——建议41:实现标准的事件模型
  9. Ubuntu 16.04 安装jdk
  10. WOX快速搜索