codeforces1257D Yet Another Monster Killing Problem

有n个怪物,每个怪物都有一个能力值a。有m个勇士,每个勇士都有一个力量P和耐力S。每天可以选择一个勇士去打怪物,必须按顺序打,如果这个勇士的能力P>=a那么就可以打败这个怪物,就必须打下一个怪物,而且最多一天只能打S个怪物。打一个怪物耐力值-1,如果力量P<a或者耐力值为0,这个勇士就得回来。这天结束,每个勇士可以使用无数次。问最少需要多少天,能把所有的怪物全部打败。

贪心即可

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<math.h>
using namespace std;
typedef long long ll;
typedef double ld;
const int INF = 0x3f3f3f3f;
const int N = 200005;
int i,j,k;
int ans,res,cnt,temp,pos;
int n,m;
int max1,max2,max3,now;
int mon[N],hp[N],nai[N];
struct node
{
    int p,s;
} hero[N];
bool cmp(node a, node b)
{
    return a.p<b.p;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        max1=0;
        max2=0;
        cin>>n;
        for(i=1; i<=n; i++)
        {
            cin>>mon[i];
            max2=max(max2,mon[i]);
        }
        cin>>m;
        for(i=1; i<=m; i++)
        {
            cin>>hero[i].p>>hero[i].s;
        }
        sort(hero+1,hero+1+m,cmp);
        if(max2>hero[m].p)
        {
            cout<<-1<<endl;
            continue;
        }
        for(i=m; i>=1; i--)
        {
            max1=max(hero[i].s,max1);
            nai[i]=max1;
        }
        for(i=1; i<=m; i++)
            hp[i]=hero[i].p;
        ans=1;
        max3=0;
        now=1;
        for(i=1; i<=n; i++)
        {
            max3=max(mon[i],max3);///贪心
            pos=lower_bound(hp+1,hp+1+m,max3)-hp;
            if(nai[pos]<(i-now+1))
            {///后面所有的勇士都不能一个人打死所有的怪必须下一天
                now=i;
                max3=mon[i];
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值