E. The Humanoid Codeforces Round #834 (Div. 3)(暴力dfs?)

题意:有一个怪兽和n个宇航员(怪兽有一个绿色药丸和一个蓝色药丸),怪兽和宇航员都有自己的一个力量值,怪兽在面对力量值小于他的宇航员时可以吃了他并且获得他的a_i/2的力量(向下取整),怪兽可以在任意时刻吃他的小药丸:

绿色药丸的效果是,把他自己的力量变成他的两倍。

蓝色药丸的效果是,把他自己的力量变成他的三倍。

怪兽想尽可能的吃足够多的宇航员,问他最多能吃多少个宇航员。

思路:首先怪物吃肯定是要从小开始吃,可以直接把数组先排序一遍。然后因为怪兽再怎么吃也只有三个小药丸,那么可以dfs三个药丸吃的顺序(也可以直接把顺序全部列出来然后都考虑一下情况),然后用sts数组标记怪兽能吃的最大力量值的人,最后直接输出就可以了。

代码:

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ;
ll m,h;
ll s[N];
int cnt[4]={0,2,2,3};
bool sts[N];
bool st[4];

void dfs(ll x,int i,int j,int sum)
{
    if(j!=0)
    x*=cnt[j];

    for(i;i<=n;i++)
    {
        if(x<=s[i])
        {
            if(sum>=3)break;
            for(int j =1;j<=3;j++)
            {
                if(!st[j])
                {
                    st[j]=1;
                    dfs(x,i,j,sum+1);
                    st[j]=0;
                }
            }
            break;
        }
        else{
            sts[i]=1;
            x+=s[i]/2;
        }
    }
}

int main()
{
	int t;
	sc_int(t);
    while(t--)
    {
        cin>>n>>m;
        memset(sts,0,sizeof sts);

        for(int i =1;i<=n;i++)
        cin>>s[i];
        sort(s+1,s+1+n);
        int sum=0;
        dfs(m,1,0,0);

        for(int i =1;i<=n;i++)
        if(sts[i])sum++;
        cout<<sum<<endl;

    }
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值