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. css四可见,部分可见和重叠半透明

    <html> <head> <title>javascript</title> <style type="text/css"& ...

  2. Jmeter调度器配置

    Jmeter的线程组设置里有一个调配器设置,用于设置该线程组下脚本执行的开始时间.结束时间.持续时间及启动延迟时间.当需要半夜执行性能测试时会用到这个功能. ps:设置调度器配置,需要将前面的循环次数 ...

  3. SpringBoot16 MockMvc的使用、JsonPath的使用、请求参数问题、JsonView、分页查询参数、JsonProperty

    1 MockMvc的使用 利用MockMvc可以快速实现MVC测试 坑01:利用MockMvc进行测试时应用上下文路径是不包含在请求路径中的 1.1 创建一个SpringBoot项目 项目脚手架 1. ...

  4. linq 条件查询与分页

    <div>姓名:<asp:TextBox ID="T1" runat="server"></asp:TextBox>< ...

  5. 一个可用模板的Xml描述

    <?xml version="1.0" encoding="utf-8"?> <VMTEMPLATE> <ID>48< ...

  6. c语言实践 给三个数输出最大的那个数

    我是怎么想的,我前面学过两个数比大小,比如有三个数,a b c,先比较a和b的大小,然后用那个较大的和c比较就得出最大的那个了.这个求三个数比大小的问题最后变化成 了两个数比大小了. int main ...

  7. 4.std::string中库函数的使用。

    为了美观,我们把输入和输出设计成如下: #include <iostream> #include <string> int main() { std::string name; ...

  8. hdu 4269 Defend Jian Ge

    #include <cctype> #include <algorithm> #include <vector> #include <string> # ...

  9. Alternative to iPhone device ID (UDID)

    Alternative to iPhone device ID (UDID) [duplicate] up vote10down votefavorite 3 Possible Duplicate:U ...

  10. springboot调用微信的jscode2session报JSONObject异常

    问题背景: 服务器为Centos6.5 JDK:OpenJDK1.7 tomcat7 项目为微信小程序api的后端代码,解密用户信息,代码是采用springboot写的 异常信息: 代码: json异 ...