代码编织梦想

Hero

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2606    Accepted Submission(s): 1169


 

Problem Description

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.

Input

The first line of each test case contains the number of enemy heroes N (1 <= N <= 20). Then N lines followed, each contains two integers DPSi and HPi, which are the DPS and HP for each hero. (1 <= DPSi, HPi <= 1000)

Output

Output one line for each test, indicates the minimum HP loss.

Sample Input

1 10 2 2 100 1 1 100

Sample Output

20 201

Author

TJU

Source

2012 Multi-University Training Contest 2

代码:先是模拟,然后优化,之后得到这么一个jiahuo ....

 1 #include<cstring>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 struct node{
 6   int HP,DSP;
 7   bool operator < (const node & a)const{
 8       return DSP*a.HP>a.DSP*HP;
 9   }
10 };
11 node st[22];
12 int main(){
13 
14   int n;
15   int ans;
16 // freopen("test.in","r",stdin);
17   while(scanf("%d",&n)!=EOF){
18       ans=0;
19      for(int i=0;i<n;i++){
20       scanf("%d%d",&st[i].HP,&st[i].DSP);
21      }
22      sort(st,st+n);
23      for(int i=0;i<n;i++){
24         for(int j=i;j<n;j++){
25              ans+=st[j].DSP*st[i].HP;
26        }
27      }
28    printf("%d\n",ans);
29   }
30 return 0;
31 }
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_72431373/article/details/127970366

hdu4310-爱代码爱编程

Problem Description 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

训练第四天之贪心算法-爱代码爱编程

概念: 所谓贪心算法是指,在对问题求解时总是做出在当前看来是最好的选择。在此种情况下做出的仅仅是在某种意义上的局部最优解。(但是局部最优解并不一定总是能得到全局最优解) 条件: 1.整体的最优解可以通过局部的最优解导出

贪心算法-爱代码爱编程

B Saving HDU 先po原题 [HDU 2111]http://acm.hdu.edu.cn/showproblem.php?pid=2111 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫

hdu 4310_行走的算法的博客-爱代码爱编程

Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(

贪心算法专题_eck_燃的博客-爱代码爱编程

贪心本质 一个贪心算法总是做出当前最好的选择,也就是说,它期望通过局部最优选择从而得到全局最优的解决方案。 ——《算法导论》 贪心算法的特点 贪心算法在解决问题只根据当前已有的信息就做出选择,而且一旦做出了选择,这个

acm贪心算法-个人理解第一阶段_nelaris的博客-爱代码爱编程

//经过一周不到的贪心训练,菜鸡突然想说点什么 //训练题目:应该是出自陕西暑假 ACM 集训入门班题目   【2017 Summer Training】入门班day1  //还没有完全补完,只是先对贪心有了初步了解 贪心,顾名思义,就是从在求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,他所做出的是在某种意义上的局部最优解

hdu 4310 hero(贪心)_qz201410的博客-爱代码爱编程

 Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1263    Accepted Submission(s): 634 Problem Description When pla

杭电acm——4310,hero(贪心)_notmuch的博客-爱代码爱编程

题意:有N个敌人,每个敌人都有血条HP和伤害DPS,你的HP无限,伤害固定为1,而且你在攻击敌人的同时,所有HP不为0的敌人都能攻击你。求出击杀所有敌人所需的最小HP损失。 原题链接:http://acm.hdu.edu.c

ignatius and the princess i(hdu-1026)_cjmhk的博客-爱代码爱编程

目录 1 题意2 思路2.1 BFS & 贪心2.1.1 时间复杂度分析2.1.2 实现 1 题意   给定一个 n

HDU 贪心专题-爱代码爱编程

☀️下面整理了几道使用贪心算法的题目,从简到难。💪 一、HDU 4310 Hero 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4310 题意为,每个Hero有DPS和HP两个属性,每个时刻都受到HP>0的敌人的攻击,而自己每个时刻只能攻击一个敌人,使其HP减一。问自己打败所有敌人消耗最小的HP量

HDU 4310 贪心算法 C++版-爱代码爱编程

Problem - 4310 (dingbacode.com)https://acm.dingbacode.com/showproblem.php?pid=4310当然是先选择攻击值最高的打了,一开始这么想,但是错了,因为攻击值高的可能血量也很高,很难打败。 所以,应该按照Dps/Hp从高到低的顺序开始攻击,Dps/Hp值越大,说明能最快速的削弱其战斗力

hdu4310 Hero 思路及题解-爱代码爱编程

Problem Description 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 f

代码随想录 | day 59 - leetcode 503. 下一个更大元素ii、leetcode 42. 接雨水_非社会人士的博客-爱代码爱编程

        今天是单调栈的第2天,第1道题是前面的延续,第2道题很难还常考。第2题双指针和DP解法重点是“当前位置的雨水量取决于左右两边柱子最高高度”,单调栈解法则要熟悉“左、中、右三个柱子各自的含义和作用”。         第1题(LeetCode 503. 下一个更大元素II)相比day 58中第1题(LeetCode 739. 每