计蒜客:islands 打炉石传说

本文展示了一个使用C++实现的游戏卡片策略算法示例,通过枚举所有可能的卡片组合,寻找成本不超过10的最大战斗力组合。算法首先读取卡片的成本、防御力和攻击力,然后计算所有可能的组合,最后找出满足条件的最大战斗力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 AC代码:

#include<iostream>
#define MAX 100
using namespace std;
struct d
{
	int cost;
	int d;
	int w;
}card[MAX],temp[MAX];
int search_for_max(struct d *temp,int count);
int main()
{
	int i,j; 
	int n,cost,d,w;
	int monster,magic;
	cin>>n; 
	for(i=0;i<n;i++)
	{
		cin>>card[i].cost>>card[i].d>>card[i].w;
		
	}
	int count=0,sum,max=-99999;
	for(i=0;i<(1<<n);i++)
	{
		sum=0;
		count=0;
		for(j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				sum+=card[j].cost;
				temp[count]=card[j];
			//	cout<<" cost , d , w : "<<temp[count].cost<<" "<<temp[count].d <<" "<<temp[count].w ; 
				count++;
			}
		}
	
		if(sum <= 10)
		{
			if(search_for_max(temp,count)>max)
			{
				max = search_for_max(temp,count);
 			}
		}	
	//cout<<endl<<" max = "<<max<<endl;
		for(j=0;j<count;j++)
		{
			temp[j].cost = -999;
			temp[j].d =-999;
			temp[j].w =-999;
		}
	}
	cout<<max;
	return 0;
 } 
 int search_for_max(struct d *temp,int count)
 {
 	int i,index1=0,index2=0;
 	int sum=0;
 	int card_monster[MAX],card_magic[MAX];
 	for(i=0;i<count;++i)
 	{
 		if(temp[i].d==0)
 		{
 			card_monster[index1++]=temp[i].w;
		}
		else
		{
		 	card_magic[index2++]=temp[i].w;
		}
	 }
	// cout<<" index1 = "<<index1;
	 if(index1==0)
	 {
	 	return 0;
	 }
	 else
	 {
	 	sum=0;
	    for(i=0;i<count;i++)
	    {
	    //	cout<<" temp[i].w = "<<temp[i].w ;
		 	sum += temp[i].w;
		}
		//cout<<" sum = "<<sum<<endl;
		return sum;	
	 }
 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ali]e

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值