题意:有一个怪兽和n个宇航员(怪兽有一个绿色药丸和一个蓝色药丸),怪兽和宇航员都有自己的一个力量值,怪兽在面对力量值小于他的宇航员时可以吃了他并且获得他的的力量(向下取整),怪兽可以在任意时刻吃他的小药丸:
绿色药丸的效果是,把他自己的力量变成他的两倍。
蓝色药丸的效果是,把他自己的力量变成他的三倍。
怪兽想尽可能的吃足够多的宇航员,问他最多能吃多少个宇航员。
思路:首先怪物吃肯定是要从小开始吃,可以直接把数组先排序一遍。然后因为怪兽再怎么吃也只有三个小药丸,那么可以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;
}