HDU 4310 Hero (贪心)
题意:给定你有 n 个敌人,你的伤害是 1,给出每个敌人的伤害,和敌人的血量,每一回合你可以攻击一个敌人,并且所有敌人都会攻击你,除非它已经死了,问你最少要多少要消耗多少血量。
析:一个很明显的贪心问题,按照 攻击 / 血量进行排序,然后一个一个的消灭就好了。
代码如下:
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <cstring>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <cctype>
- #include <cmath>
- #include <stack>
- #include <sstream>
- #include <list>
- #include <assert.h>
- #include <bitset>
- #include <numeric>
- #define debug() puts("++++")
- #define gcd(a, b) __gcd(a, b)
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define fi first
- #define se second
- #define pb push_back
- #define sqr(x) ((x)*(x))
- #define ms(a,b) memset(a, b, sizeof a)
- #define sz size()
- #define be begin()
- #define ed end()
- #define pu push_up
- #define pd push_down
- #define cl clear()
- #define lowbit(x) -x&x
- //#define all 1,n,1
- #define FOR(i,n,x) for(int i = (x); i < (n); ++i)
- #define freopenr freopen("in.in", "r", stdin)
- #define freopenw freopen("out.out", "w", stdout)
- using namespace std;
- typedef long long LL;
- typedef unsigned long long ULL;
- typedef pair<int, int> P;
- const int INF = 0x3f3f3f3f;
- const LL LNF = 1e17;
- const double inf = 1e20;
- const double PI = acos(-1.0);
- const double eps = 1e-10;
- const int maxn = 20 + 5;
- const int maxm = 700 + 10;
- const LL mod = 1000000007;
- const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
- const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
- const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
- int n, m;
- const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- inline bool is_in(int r, int c) {
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- inline int readInt(){ int x; scanf("%d", &x); return x; }
- struct Node{
- int dps, hp;
- bool operator < (const Node &p) const{
- return p.dps * hp < p.hp * dps;
- }
- };
- Node a[maxn];
- int main(){
- while(scanf("%d", &n) == 1){
- for(int i = 0; i < n; ++i)
- scanf("%d %d", &a[i].dps, &a[i].hp);
- sort(a, a + n);
- LL ans = 0, cnt = 0;
- for(int i = 0; i < n; ++i){
- cnt += a[i].hp;
- ans += a[i].dps * cnt;
- }
- printf("%I64d\n", ans);
- }
- return 0;
- }
HDU 4310 Hero (贪心)的更多相关文章
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 4310 Hero
这道题是道算是一道很简单的贪心题了,但是要注意排序的依据,这道题是按照dps/hp的从大到小排序的,然后计算总的sumhp即可. #include"iostream" #inclu ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- HDU 4310 贪心
题意 在游戏中你的dps为1但是hp无限 给出n个敌人的dps与hp 你一秒能打掉一个敌人你的dps的hp 当你输出的时候 所有活着的敌人都会打你 求杀死所有敌人时你掉的最少hp 一开始想错了 排序的 ...
- hdu 2037简单贪心--活动安排问题
活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
- hdu 4864 Task (贪心 技巧)
题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...
随机推荐
- jquey中json字符串与json的转换(转)
<!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...
- sql查询 !='' 和 is not null的区别
select * from table where a is not null 会把有内容的和内容为空的都查出来而select * from table where a != '' 只会把有内容的查出 ...
- String.format的用法
有些时候,对于一些东西,不是没有简单的方法,而是我们没有接触到过 String.format();即创建格式化的字符串,里面有很多的通配使用符号,我这里说一下我接触到的,以后接触到其他的再填坑 它的内 ...
- 安装scrapy 出现error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools 错误
安装scrapy 出现以下 错误: error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C ...
- django ORM 增删改查 模糊查询 字段类型 及参数等
ORM 相关 #sql中的表 #创建表: CREATE TABLE employee( id INT PRIMARY KEY auto_increment , name VARCHAR (), gen ...
- windbg 加载dump监测蓝屏原因时出现重复的星星框提示解决办法
加载dump文件出现了重复上边的信息 总结: 要reload一下环境,说明符号库未加载出现的错误,!sym noisy 显示详细信息 ,reload重载符号库,未找到的,从服务器进行下载, 注意,第一 ...
- hdu 1429 (bfs+状态压缩) 胜利大逃亡续
http://acm.hdu.edu.cn/showproblem.php?pid=1429 典型的状压搜索,在普通的搜索基础上,利用二进制的特性记录钥匙与门, 二进制的每一位代表一把钥匙,比如说拿到 ...
- spring MVC中Dubbo的配置
1.服务提供方的bubbo配置: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=& ...
- CSS中(font和background)的简写形式
转自:http://blog.csdn.net/shenzhennba/article/details/7356095 1.字体属性主要包括下面几个:font-family(字体族): “Arial” ...
- shell脚本${}、##和%%使用范例
file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值: ${file#*/}:删掉第一个 / 及其左边的字符串:dir1/dir2/dir3/my.fi ...