HDU4310HERO贪心问题
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.
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 25
#define eps 1e-8
using namespace std;
//用一个结构体来储存敌人的2个属性
typedef struct cw{
int dps;
int hp;
} sc;
sc enemy[N];
int cmp(sc x,sc y)
{
return 1.0*x.dps/x.hp-1.0*y.dps/y.hp<eps;//比较浮点数大小会有误差
}
int main()
{
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d %d",&enemy[i].dps,&enemy[i].hp);
}
if(n==)printf("%d\n",enemy[].dps*enemy[].hp);
else {
sort(enemy,enemy+n,cmp);//以单位血量DPS大小排序
int sum=;
for(int i=n-;i>=;i--){
//这是你杀一个enemy时受到的伤害
sum+=enemy[i].dps*enemy[i].hp;
for(int j=;j<i;j++){
//这是其他enemy同时对你造成的伤害
sum+=enemy[j].dps*enemy[i].hp;
}
}
printf("%d\n",sum);
}
}
return ;
}
HDU4310HERO贪心问题的更多相关文章
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
- 【贪心】HDU 1257
HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...
随机推荐
- MyEclipse10中配置WebLogic10
MyEclipse10中配置WebLogic10 1.双击打开MyEclipse10,依次操作"Window--->Preferences" 2.在左侧菜单中找到" ...
- 三十天学不会TCP,UDP/IP网络编程 - 绅士的开始
经过了过年的忙碌和年初的懈怠一切的日子,我又开始重新更新了~这是最新的一篇~完整版可以去gitbook(https://www.gitbook.com/@rogerzhu/)看到. 如果对和程序员有关 ...
- java的System.getProperty()获取的值
public class SystemProperty { public static void main(String args[]) { System.out.println("java ...
- 移动端开发底部元素margin-bottom失效解决办法
一.情景 记得之前开发一个微信端页面时,发现页面底部元素margin-bottom在ios下失效,在安卓内正常...... 1.safari浏览器内页面底部元素设置margin-bottom失效: 2 ...
- 关于spring事务注解实战
1.概述 spring的事务注解@Transaction 相信很多人都用过,而@Transaction 默认配置适合80%的配置. 本篇文章不是对spring注解事务做详细介绍,而是解决一些实际场景下 ...
- TestLink和RedMine的集成
1. TestLink的安装 1.1. TestLink简介 TestLink是一个php语言开发的开源免费的测试管理工具,包括产品测试需求,测试计划,测试用例的创建和执行, ...
- POJ - 2828
题意 输入队伍长度n 接下来n行,a,b 表示b插在队伍的a处 求队伍最后的情况 题解 刚开始并不知道要用线段树,经大佬点悟,发现最后插入的位置就是对应的a.所以可以从后往前依次插入,每次的位置pos ...
- [BZOJ1002] [FJOI2007] 轮状病毒 (数学)
Description 给定n(N<=100),编程计算有多少个不同的n轮状病毒. Input 第一行有1个正整数n. Output 将编程计算出的不同的n轮状病毒数输出 Sample Inpu ...
- [BZOJ4291] [PA2015] Kieszonkowe
Description 给定n个数,请从中选出若干个数,使得总和为偶数,请最大化这个总和. Input 第一行包含一个正整数n(1<=n<=1000000). 第二行包含n个正整数a_1 ...
- 踩坑の SpringMVC文件上传
环境准备 添加两个jar包 commons-fileupload-1.2.2.jar commons-io-2.4.jar 配置要求 在springmvc.xml中配置multipart类型解 ...