当前位置: 首页 > 工具软件 > Hero Solution > 使用案例 >

- Hero

彭弘方
2023-12-01
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>


using namespace std;


struct hero
{
    double hp;
    double dps;
}h[21];


bool cmp(hero a, hero b)
{
    return a.hp/a.dps < b.hp/b.dps;
}
int main()
{
    int n, i, all;
    int sum;
    while(~scanf("%d", &n))
    {
        sum = 0;
        for(i=0; i<n; i++)
        {
            scanf("%lf%lf", &h[i].hp, &h[i].dps);
            sum += h[i].dps;
        }




        sort(h, h+n, cmp);


        all = 0;
        for(i=0; i<n; i++)
        {
            all += h[i].hp * sum;
            sum -= h[i].dps;
        }
        printf("%d\n", all);
    }
}
 类似资料: