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,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...
随机推荐
- C语言视频简介
通过学习<C语言基础视频教程>,可以让你对C语言有一个基础的了解,并且会编写一些基础的程序,本次视频主要讲解的内容有: 1. 数字的进制转换 2. 变量.运算符和表达式 3. 流程控制语句 ...
- R语言︱情感分析—词典型代码实践(最基础)(一)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 笔者寄语:词典型情感分析对词典要求极高,词典中 ...
- CSS3之Border-radius
1.属性介绍 border-radius:none|12.3px,取值不可为负数,表示边框圆角 相关属性:border-top-right-radius , border-bottom-right-r ...
- Error Code: 1414. OUT or INOUT argument 2 for routine company.new_procedure is not a variable or NEW
1.错误描述 16:27:36 call new_procedure(20150112,1) Error Code: 1414. OUT or INOUT argument 2 for routine ...
- 致IT同仁 — IT人士常犯的17个职场错误
记得刚参加工作时(那是97年),中国的IT刚刚兴起,那时,作为一个IT人士是一件很光荣的事,而那时的我正在做电气和电子相关的工作.99年第一次跳槽,进入了IT行业做软件开发.至今,中国的IT已经走过了 ...
- hdu3081 Marriage Match II
新年第一篇,又花了一早上,真是蠢啊! 二分+网络流 之前对于讨论哪些人是朋友的时候复杂度过高 直接n3的暴力虽然看起来复杂度高,其实并不是每次都成立 #include<bits/stdc++.h ...
- 基于 OS X Mavericks 系统
基于 OS X Mavericks 系统远景论坛黑苹果区新手引导 常见疑难解答 以及必要知识普及帖 请善用论坛搜索功能 认真仔细地阅读置顶帖里的教程以及注意事项 前言:之前建立10.9区求助规范帖时, ...
- 利用GDI+在Winfrom绘制验证码
string yzm: private void yangzhengma() { Bitmap bt = new Bitmap(70,22);//创建位图对象 Graphics gs = Graphi ...
- 异常-----springmvc + ajaxfileupload解决ajax不能异步上传图片的问题。java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.
说明这个问题产生的原因主要是form表单上传图片的时候必须是Content-Type:"multipart/form-data,这种格式的,但是ajax在页面不刷新的情况下去加载的时候只会把 ...
- 纯CSS实现二级导航下拉菜单--css的简单应用
思想:使用css的display属性控制二级下拉菜单的显示与否.当鼠标移动到一级导航菜单的li标签时,显示二级导航菜单的ul标签.由于实现起来比较简单,所以在这里直接给出了参考代码. 1.纯CSS二级 ...