HDU题面:没有中文版的 http://acm.hdu.edu.cn/showproblem.php?pid=4310
问题的关键是怎么排序的问题,也就是优先击杀的问题,这里主要有2种排序方式,一种是利用sort函数来排序,cmp函数代码为:
int cmp(st a,st b)
{
return a.DPS/a.HP>b.DPS/b.HP;/先杀输出高血薄的比如说ADC(阴险)
}
优先队列重载AC代码如下
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
struct ss
{
int dpsi;
int hpsi;
bool friend operator<(const ss &a,const ss &b)
{
return a.hpsi*b.dpsi>b.hpsi*a.dpsi;//优先击杀权重高的
}
};
int main(void)
{
int N;
while(cin>>N)
{
priority_queue<ss>pp;
int sumdps=0,losehps=0;
while(N--)
{
ss temp;
scanf("%d%d",&temp.dpsi,&temp.hpsi);
pp.push(temp);
sumdps+=temp.dpsi;//以后每回合敌人造成的DPS
}
while(pp.empty()!=true)
{
ss temp=pp.top();
pp.pop();
losehps+=sumdps*temp.hpsi;
sumdps-=temp.dpsi;
}
cout<<losehps<<endl;
}
return 0;
}
很明显,2者的区别只是做了多项式运算的差别。