[贪心] HDU 3979 Monster

题意

V11是一个无敌的人(打不死),但是他的攻击力有限,每回合怪物和v11同时互相攻击,问最少V11受到的伤害、

思路

有点要绕hhh
开始的时候可能会认为是攻击力越高越先处理。但是仔细考虑之后贪心点不仅仅由攻击力决定,还要它的生命值同时决定。勇士在攻击一个怪兽的同时别的怪兽也在攻击勇士,他们的伤害也在叠加。所以优先消灭的怪兽有两个因素同时的决定即有怪兽的攻击力和生命值的比值决定,攻击和生命值比值高的怪兽需要先处理掉。

觉得另一个的数学公式更直观准确,不过更难想的感觉hhh
通过比较两个怪物到底先杀任意一个会受到的伤害,列出公式,来确定到底对哪个值贪心

代码

// https://blog.csdn.net/u011806194/article/details/51897908
// https://blog.csdn.net/qq_32866009/article/details/50698255

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn = 10000 + 10;

struct Monster {
    int times, atk;

    bool operator< ( const Monster &rhs ) const { return times * rhs.atk < rhs.times * atk; }
} mon[ maxn ];

int n, m;
int main () {
    int T;
    scanf ( "%d", &T );
    for ( int ks = 1; ks <= T; ++ks ) {
        scanf ( "%d%d", &n, &m );

        for ( int i = 0; i < n; ++i ) {
            int hp, atk;
            scanf ( "%d%d", &hp, &atk );
            mon[ i ].times = ( hp + m - 1 ) / m;
            mon[ i ].atk = atk;
        }

        sort ( mon, mon + n );

        int sum = 0;
        ll ans = 0;
        for ( int i = 0; i < n; ++i ) {
            sum += mon[ i ].times;
            ans += sum * mon[ i ].atk;
        }

        printf ( "Case #%d: %lld\n", ks, ans );
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值