sicily 1003. Hit or Miss

代码中有注释,应该看得懂

判断游戏不会结束时,大概设置了参数为13   if (giveCount[i] > 13*q[i].size() )   没偿试13换成其他参数行不行,反正2是不行的

#include <cstdlib>
#include <iostream>
#include <queue>
#include <memory.h>

using namespace std;


int main()
{
    int testCase;
    cin >> testCase;
    for (int testCount = 1; testCount <= testCase; testCount++){
        queue<int> q[11];
        int count[11], give[11],end[11],giveCount[11],total=0;
		//count是每个人的数数,give是给下一个人的牌,end是每一个玩家最后丢弃的牌,giveCount是每两张丢弃的牌数数的间隔
		//total是记录被最后一个人丢弃牌的总数
        bool finish = false, unwin = false;
        memset(count,0,sizeof(count));
		memset(giveCount,0,sizeof(giveCount));
        memset(end,0,sizeof(end));
        int player;
        cin >> player;
        int num;
        for (int j = 0 ; j < 52; j++){
            cin >> num;
            q[0].push(num);
        }
        while (!finish && !unwin)
        {
              memset(give,0,sizeof(give));
              finish = true;
              for (int i = 0 ; i < player; i++){
                  if (!q[i].empty()){
                     finish = false;
                     if (count[i] + 1 == q[i].front()){   //数数与当前牌匹配 
						   giveCount[i] = 0;	
                           give[i+1] = q[i].front();
						   end[i] = q[i].front();
                           q[i].pop();
						   if ( i == player - 1){	  //最后一个人出完牌
							  total++;
							  if (total >=52)		  //丢弃牌大于52,则游戏结束
								finish = true;
						   }
                     }
                     else{//不匹配 
                           q[i].push(q[i].front());
                           q[i].pop();
						   giveCount[i]++;
							if (giveCount[i] > 13*q[i].size() )
								unwin = true;

                     }
					 count[i] = (count[i]+1)%13;
                  }
                  if (give[i] != 0 )	//加上上一个玩家所给的牌
                      q[i].push(give[i]);		
              }
        }
        cout << "Case " << testCount << ":";
		if (finish)
			for (int i = 0 ; i < player; i++)
				cout <<" "<<end[i];
		if (unwin)
			cout << " unwinnable";
        cout << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值