hdu4310
来源:互联网 发布:淘宝一块钱包邮的东西 编辑:程序博客网 时间:2024/06/06 14:58
When playing DotA with god-like rivals and pig-like team members, you have to face an embarrassing situation: All your teammates are killed, and you have to fight 1vN.
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.
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.
110 22100 11 100
20201
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct node{ int demage, hp;}nn[22];bool cmp(const node a, const node b){ return a.demage*b.hp > a.hp*b.demage; /*注意这里此题的核心就这一步*/}int main(){ int n; while(scanf("%d", &n) != EOF){ memset(nn, 0, sizeof(nn)); for(int i = 0; i < n; i++){ scanf("%d%d", &nn[i].demage, &nn[i].hp); /*很坑输入顺序是demage,hp*/ } sort(nn, nn+n, cmp); for(int i = 1; i < n; i++){ nn[i].hp = nn[i-1].hp + nn[i].hp; } int sum = 0; for(int i = 0; i < n; i++){ sum += (nn[i].demage * nn[i].hp); } printf("%d\n", sum); } return 0;}
0 0
- hdu4310
- hdu4310
- hdu4310
- HDU4310:Hero
- hdu4310(贪心)
- HDU4310贪心
- HERO(HDU4310)
- hdu4310 hero
- hdu4310 Hero
- hdu4310 Hero 贪心证明
- hdu4310 Hero 贪心
- hdu4310 Hero(贪心)
- hdu4310 Hero (贪心)
- hdu4310 Hero(贪心)
- hdu4310(贪心)
- hdu4310(贪心)
- hdu4310 Hero(贪心)
- 简单典型贪心---(解题报告)HDU4310---Hero
- Hive语法简述(基础部分)
- oracleServiceXxx服务不见了
- GDOI2017 总结
- redis代码实战
- HTML给div设置百分比高度无效问题
- hdu4310
- 基数排序法
- zoj1076Gene Assembly
- 计算机视觉学习步骤
- 数据库隔离级别
- Java 线程池
- 上传excel+验证是否excel+解析+校验数据
- 从0到有-如何搭建个人博客
- MySQL表的增删改查