题意:给定你有 n 个敌人,你的伤害是 1,给出每个敌人的伤害,和敌人的血量,每一回合你可以攻击一个敌人,并且所有敌人都会攻击你,除非它已经死了,问你最少要多少要消耗多少血量。

析:一个很明显的贪心问题,按照 攻击 / 血量进行排序,然后一个一个的消灭就好了。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #include <sstream>
  17. #include <list>
  18. #include <assert.h>
  19. #include <bitset>
  20. #include <numeric>
  21. #define debug() puts("++++")
  22. #define gcd(a, b) __gcd(a, b)
  23. #define lson l,m,rt<<1
  24. #define rson m+1,r,rt<<1|1
  25. #define fi first
  26. #define se second
  27. #define pb push_back
  28. #define sqr(x) ((x)*(x))
  29. #define ms(a,b) memset(a, b, sizeof a)
  30. #define sz size()
  31. #define be begin()
  32. #define ed end()
  33. #define pu push_up
  34. #define pd push_down
  35. #define cl clear()
  36. #define lowbit(x) -x&x
  37. //#define all 1,n,1
  38. #define FOR(i,n,x) for(int i = (x); i < (n); ++i)
  39. #define freopenr freopen("in.in", "r", stdin)
  40. #define freopenw freopen("out.out", "w", stdout)
  41. using namespace std;
  42.  
  43. typedef long long LL;
  44. typedef unsigned long long ULL;
  45. typedef pair<int, int> P;
  46. const int INF = 0x3f3f3f3f;
  47. const LL LNF = 1e17;
  48. const double inf = 1e20;
  49. const double PI = acos(-1.0);
  50. const double eps = 1e-10;
  51. const int maxn = 20 + 5;
  52. const int maxm = 700 + 10;
  53. const LL mod = 1000000007;
  54. const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
  55. const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
  56. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  57. int n, m;
  58. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  59. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  60. inline bool is_in(int r, int c) {
  61. return r >= 0 && r < n && c >= 0 && c < m;
  62. }
  63. inline int readInt(){ int x; scanf("%d", &x); return x; }
  64.  
  65. struct Node{
  66. int dps, hp;
  67. bool operator < (const Node &p) const{
  68. return p.dps * hp < p.hp * dps;
  69. }
  70. };
  71.  
  72. Node a[maxn];
  73.  
  74. int main(){
  75. while(scanf("%d", &n) == 1){
  76. for(int i = 0; i < n; ++i)
  77. scanf("%d %d", &a[i].dps, &a[i].hp);
  78. sort(a, a + n);
  79. LL ans = 0, cnt = 0;
  80. for(int i = 0; i < n; ++i){
  81. cnt += a[i].hp;
  82. ans += a[i].dps * cnt;
  83. }
  84. printf("%I64d\n", ans);
  85. }
  86. return 0;
  87. }

  

HDU 4310 Hero (贪心)的更多相关文章

  1. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  2. hdu 4310 Hero

    这道题是道算是一道很简单的贪心题了,但是要注意排序的依据,这道题是按照dps/hp的从大到小排序的,然后计算总的sumhp即可. #include"iostream" #inclu ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  5. HDU 4310 贪心

    题意 在游戏中你的dps为1但是hp无限 给出n个敌人的dps与hp 你一秒能打掉一个敌人你的dps的hp 当你输出的时候 所有活着的敌人都会打你 求杀死所有敌人时你掉的最少hp 一开始想错了 排序的 ...

  6. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

  9. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

随机推荐

  1. jquey中json字符串与json的转换(转)

    <!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...

  2. sql查询 !='' 和 is not null的区别

    select * from table where a is not null 会把有内容的和内容为空的都查出来而select * from table where a != '' 只会把有内容的查出 ...

  3. String.format的用法

    有些时候,对于一些东西,不是没有简单的方法,而是我们没有接触到过 String.format();即创建格式化的字符串,里面有很多的通配使用符号,我这里说一下我接触到的,以后接触到其他的再填坑 它的内 ...

  4. 安装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 ...

  5. django ORM 增删改查 模糊查询 字段类型 及参数等

    ORM 相关 #sql中的表 #创建表: CREATE TABLE employee( id INT PRIMARY KEY auto_increment , name VARCHAR (), gen ...

  6. windbg 加载dump监测蓝屏原因时出现重复的星星框提示解决办法

    加载dump文件出现了重复上边的信息 总结: 要reload一下环境,说明符号库未加载出现的错误,!sym noisy 显示详细信息 ,reload重载符号库,未找到的,从服务器进行下载, 注意,第一 ...

  7. hdu 1429 (bfs+状态压缩) 胜利大逃亡续

    http://acm.hdu.edu.cn/showproblem.php?pid=1429 典型的状压搜索,在普通的搜索基础上,利用二进制的特性记录钥匙与门, 二进制的每一位代表一把钥匙,比如说拿到 ...

  8. spring MVC中Dubbo的配置

    1.服务提供方的bubbo配置: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=& ...

  9. CSS中(font和background)的简写形式

    转自:http://blog.csdn.net/shenzhennba/article/details/7356095 1.字体属性主要包括下面几个:font-family(字体族): “Arial” ...

  10. shell脚本${}、##和%%使用范例

    file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值: ${file#*/}:删掉第一个 / 及其左边的字符串:dir1/dir2/dir3/my.fi ...