Hero HDU4310 贪心
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.
InputThe 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)OutputOutput one line for each test, indicates the minimum HP loss.Sample Input
1
10 2
2
100 1
1 100
Sample Output
20
201
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#define MAXN 25
#define INF 0x3f3f3f3f
#define eps 1e-11 + 1e-12/2
typedef long long LL; using namespace std;
/*
推公式
A的伤害<B的伤害 即
BD*AH <AD*BH
*/
struct node
{
int d, h;
};
node a[MAXN];
bool cmp(node l, node r)
{
return r.d*l.h < r.h*l.d;
}
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
for (int i = ; i < n; i++)
scanf("%d%d", &a[i].d, &a[i].h);
sort(a, a + n, cmp);
int time = , sum = ;
for (int i = ; i < n; i++)
{
time += a[i].h;
sum += (a[i].d)*time;
}
printf("%d\n", sum);
}
}
Hero HDU4310 贪心的更多相关文章
- hdu4310 贪心
考虑每次血口的要少 就按照一滴血多少伤害来计算.由于直接相除有小数.考虑x/y > a/b => x*b >y*a; #include<stdio.h> #inclu ...
- HDU-4310 Hero 贪心问题
题目链接:https://cn.vjudge.net/problem/HDU-4310 题意 打dota,队友太菜,局势变成1vN.还好你开了挂,hp无限大(攻击却只有一点每秒-_-). 但是你并不想 ...
- hdu4310 - Hero - 简单的贪心
2017-08-26 15:25:22 writer:pprp 题意描述: • 1 VS n对战,回合制(你打他们一下,需要受到他们所有存活人的攻击)• 你的血量无上限,攻击力为1• 对手血量及攻击 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- 暑假集训(2)第八弹 ----- Hero(hdu4310)
K - Hero Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:65536KB 64bit ...
- HDU4310:Hero
Problem Description When playing DotA with god-like rivals and pig-like team members, you have to fa ...
- HDU 4310 Hero (贪心)
题意:给定你有 n 个敌人,你的伤害是 1,给出每个敌人的伤害,和敌人的血量,每一回合你可以攻击一个敌人,并且所有敌人都会攻击你,除非它已经死了,问你最少要多少要消耗多少血量. 析:一个很明显的贪心问 ...
- 2016HUAS暑假集训训练2 K - Hero
题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/K 这也是一道贪心题,刚开始写时以为只要对每一敌人的攻击和血的乘积进行从小到大排序即 ...
- 2016HUAS_ACM暑假集训2K - Hero(英雄)
这也属于一个贪心题.关键是排序的依据. 这题排序的依据是敌人的伤害/血量(DPS/HP),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...
随机推荐
- Mybatis Generator插件升级版
一.目的: 1. *mapper.java 文件名称 改为*DAO.java2. mapper以及mapper.xml 重复执行,只会覆盖原模板方法,不会覆盖自定义方法3. 实体类添加中文注释 二.步 ...
- 拦截机制中Aspect、ControllerAdvice、Interceptor、Fliter之间的区别详解
Spring中的拦截机制,如果出现异常的话,异常的顺序是从里面到外面一步一步的进行处理,如果到了最外层都没有进行处理的话,就会由tomcat容器抛出异常. 1.过滤器:Filter :可以获得Http ...
- C#和C++的区别(一)
C#特性 1.指针可以有++.--运算,引用不可以运算: 2.类或结构的默认访问类型是internal 类的所有成员,默认是private 3.属性:用于定义一些命名特性,通过它来读取和写入相关的特性 ...
- NodeJs学习记录(三)vscode下启动一个nodejs的web工程
2017/01/23 星期一 前言:根据手上现成的一个web工程来学习 1.配置vscode使其可以识别nodejs的页面文件.ejs 2.先把项目拖拽至vscode的编辑界面,在"查看&q ...
- JS求斐波那契数列的N项
第一种求法: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF- ...
- java实现麦克风自动录音
最近在研究语音识别,使用百度的sdk.发现只有识别的部分,而我需要保存音频文件,并且实现当有声音传入时自动生成音频文件. 先上代码: public class EngineeCore { String ...
- 处理sql锁死问题
--SQL Server死锁的查询方法: exec master.dbo.p_lockinfo 0,0; ---显示死锁的进程,不显示正常的进程 exec master.dbo.p_locki ...
- JMeter怎样测试WebSocket,示例演示(二)
一.测试案例演示 以 http://www.websocket.org/echo.html 网站为例. 地址为:ws://echo.websocket.org 二.长连接的影响 1.没有勾选stre ...
- offset 后 指针数组转换
AcDbObjectId pidoffset; AcDbPolyline *plineOffset; AcDbVoidPtrArray ptarr=NULL; pline->getOffsetC ...
- Python爬虫:抓取手机APP的数据
摘要 大多数APP里面返回的是json格式数据,或者一堆加密过的数据 .这里以超级课程表APP为例,抓取超级课程表里用户发的话题. 1.抓取APP数据包 表单: 表单中包括了用户名和密码,当然都是加密 ...