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 [题目类型]贪心 & ...
随机推荐
- MySQL exists 和 not exists 的用法
有一个查询如下: 1 SELECT c.CustomerId, c.CompanyName 2 FROM Customers c 3 WHERE EXISTS( 4 SELECT ...
- jumpserver(0.3.2版本)开源跳板机系统部署
1. 介绍 JumpServer亮点: 集成Ansible,批量执行命令: 支持WebTerminal wiki地址:https://github.com/jumpserver/jumpserver/ ...
- apache-storm-1.0.3安装部署
CentOS7-1 CentOS7-2 CentOS7-3 CentOS7-4 nimbus supervisor supervisor supervisor core(UI) 1.首 ...
- 用python 实现生成双色球小程序
生成双色球小程序: #输入n,随机产生n条双色球号码,插入n条数据库 #表结构: seq CREATE TABLE `seq` ( `id` int(11) NOT NULL AUTO_INCREME ...
- Check back what the kd 6 for more info
Representing a shout-to his fans in China, the What the KD 6 may be the product of NIKEiD's Player E ...
- 字符串的partition函数
partition函数 str1='sdga2a34'aa=str1.partition('a') print(aa) """ ('sdg', 'a', '2a34') ...
- 基于bootstrap metronic-responsive-admin-dashboard-template 开发管理后台
简单介绍 我们这个系统是基于bootstrap metronic-responsive-admin-dashboard-template 这个模板开发的.版本用的是metronic_v4.5.2 效果 ...
- koa2+mongoose搭建框架模型
由于学的是java,所以此框架多少有点java的影子,我觉得不必排斥语言,只要思想好,所有语言均可以通用.项目分以下几层 app.js项目启动入口,类似于main函数 controller-view层 ...
- Java GC随笔
最近发生了一些C#程序运行时的一些问题,发现是GC导致的问题,然后稍微研究了一下GC,因为知道Java的GC要比.NET稍微复杂一点,所以我觉得要是能弄懂Java的GC的原理,对.NET的GC的理解也 ...
- Submine Text 快捷键
Ctrl+Shift+P:打开命令面板 Ctrl+P:搜索项目中的文件 Ctrl+G:跳转到第几行 Ctrl+W:关闭当前打开文件 Ctrl+Shift+W:关闭所有打开文件 Ctrl+Shift+V ...