hdu4310 - Hero - 简单的贪心
2017-08-26 15:25:22
writer:pprp
题意描述:
• 1 VS n对战,回合制(你打他们一下,需要受到他们所有存活人的
攻击)
• 你的血量无上限,攻击力为1
• 对手血量及攻击力给定
• 消灭所有敌人掉最少的血量
• n ≤ 20
贪心的去做,应该优先解决那些攻击力高血量低的敌人,所以应该按照 攻击力/血量 降序排列然后处理就好了
代码如下:
/*
@theme:hdu 4310
@writer:pprp
@declare:简单的贪心算法 将攻击力/血量最高的敌人先进攻下来就行了
@date:2017/8/26
*/
#include <bits/stdc++.h> using namespace std;
class enemy
{
public:
double dps;
double hp;
} emy[]; struct cmp
{
bool operator()(const enemy& a, const enemy&b)
{
return a.dps/a.hp > b.dps/b.hp;
}
}; int main()
{
int n; while(cin >> n && n >= && n <= )
{
double ans = ;
double sum_dps = ;
for(int i = ; i < n ; i++)
{
cin >> emy[i].dps >> emy[i].hp;
sum_dps += emy[i].dps;
} sort(emy, emy + n,cmp()); // for(int i = 0 ; i < n ;i++)
// {
// cout << emy[i].dps << " " << emy[i].hp << endl;
// } for(int i = ; i < n ; i++)
{
if(i == )
{
ans += emy[].hp * sum_dps;
}
else
{
sum_dps -= emy[i-].dps;
ans += emy[i].hp * sum_dps;
}
} cout << ans << endl;
}
return ;
}
hdu4310 - Hero - 简单的贪心的更多相关文章
- HDU-4310 Hero 贪心问题
题目链接:https://cn.vjudge.net/problem/HDU-4310 题意 打dota,队友太菜,局势变成1vN.还好你开了挂,hp无限大(攻击却只有一点每秒-_-). 但是你并不想 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
- 排队打饭 sdut 2443【最简单的贪心法应用举例】
排队打饭 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...
- HDOJ 2037简单的贪心算法
代码: #include<iostream> using namespace std; int main() { int n,s,t1[100],t2[100],i,t,j; while( ...
- poj 1065 简单的贪心算法
题意大概是:有一组木头需要处理,每块木头有长度,重量两个属性,处理的前一块木头长len,重wei,当下一块木头的len1,与wei1满足:len1>len&&wei1>we ...
- HDOJ-6645(简单题+贪心+树)
Stay Real HDOJ-6645 由小根堆的性质可以知道,当前最大的值就在叶节点上面,所以只需要排序后依次取就可以了. #include<iostream> #include< ...
- ACM_ICPC hdu-2111(简单贪心算法)
一道非常简单的贪心算法,但是要注意输入的价值是单位体积的价值,并不是这个物品的总价值!#include <iostream> #include <stdio.h> #inclu ...
- ACM_Appleman and Card Game(简单贪心)
Appleman and Card Game Time Limit: 2000/1000ms (Java/Others) Problem Description: Appleman has n car ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
随机推荐
- Java SAX handle xml
https://www.journaldev.com/1198/java-sax-parser-example Java SAX Parser Example SAX Parser in java ...
- Zipline Trading Calendars
Trading Calendars What is a Trading Calendar? 什么是交易日历? A trading calendar represents the timing info ...
- vue中回车键登录
created() { let that = this; document.onkeypress = function(e) { var keycode = document.all ? event. ...
- VC++SDK编程——模拟时钟
#include <Windows.h> #include <tchar.h> #include <math.h> typedef struct Time { in ...
- squee_spoon and his Cube VI---郑大校赛(求最长子串)
市面上最常见的魔方,是三阶魔方,英文名为Rubik's Cube,以魔方的发明者鲁比克教授的名字命名.另外,二阶魔方叫Pocket Cube,它只有2*2*2个角块,通常也就比较小:四阶魔方叫Reve ...
- vim 设置字体和解决乱码
在 C:\Program Files (x86)\Vim 目录中的 _vimrc 文件中加入下面两行 set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bo ...
- 不再依赖A*,利用C++编写全新寻路算法
一,说在前面的话 大概在半年前,看见一到信息竞赛题:在任意方格阵中设置障碍物,确定起始点后,求这两点之间路径.当时觉得蛮有意思的,但是没有时间去做,今天花了两个小时来实现它.据说有一个更高级的寻路算法 ...
- VirtualBox AndroidX86 网络设置
在Virtualbox中,把虚拟机网络设为“网络地址转换(NAT)”模式,高级中控制芯片(T)选择:PCnet-FAST III(Am79C973), 然后启动你的android-x86 4.0虚拟机 ...
- The Cheap KD 8 is rumored to arrive online
Nike and also the Oklahoma City Thunder star revealed the Cheap KD 8, which they are calling probabl ...
- 函数对象[条款18]---《C++必知必会》
有时需要一些行为类似于函数指针的东西,但函数指针显得笨拙.危险而且过时(让我们承认这一点).通常最佳方式是使用函数对象(function object)取代函数指针. 与智能指针一样,函数对象也是一个 ...