HDU 4930 Fighting the Landlords

Doubi Gao3 posted @ 2014年8月08日 12:30 in acm with tags 模拟 , 1063 阅读

给定斗地主的规则以及两幅手牌,然后判断是否在这一轮内你不会输给对手或者出完了全部手牌。

在比赛中我判断所有的情况,这样比较麻烦。其实可以把Bomb、Tri、Pair拆开分别去判断,有很多细节需要注意。

 

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int x[20], y[20];

int Win(int n)
{
	if(n == 4 || n == 6) //炸弹带 
	{
		for(int i = 17; i >= 3; i--)
		{
			if(x[i] == 4) return 1;
		}
	}
	if(n == 5) //3带2 
	{
		int Tri = 0, Dou = 0;
		for(int i = 17; i >= 3; i--)
		{
			if(x[i] == 3) Tri = 1;
			if(x[i] == 2) Dou = 1;
		}
		if(Tri && Dou) return 1;
	}
	if(n == 4) //3带1 
	{
		for(int i = 17; i >= 3; i--)
		{
			if(x[i] == 3) return 1;
		}
	}
	if(n == 3) //三个 
	{
		for(int i = 17; i >= 3; i--)
		{
			if(x[i] == 3) return 1;
		}
	}
	if(n == 2) //Double 
	{
		for(int i = 17; i >= 3; i--)
		{
			if(x[i] == 2) return 1;
		}
	}
	if(n == 1) return 1; //一个 
	
	return 0;
}

int main()
{
	int T;
	for(scanf("%d", &T); T > 0; T--)
	{
		char s[20];
		scanf("%s", s);
		
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		
		for(int i = 0; s[i]; i++)
		{
			int t;
			if(s[i] == 'T') t = 10;
			else if(s[i] == 'J') t = 11;
			else if(s[i] == 'Q') t = 12;
			else if(s[i] == 'K') t = 13;
			else if(s[i] == 'A') t = 14;
			else if(s[i] == '2') t = 15;
			else if(s[i] == 'X') t = 16;
			else if(s[i] == 'Y') t = 17;
			else t = s[i]-'0';
			x[t]++;
		}
		
		int len = strlen(s);
		scanf("%s", s);
		for(int i = 0; s[i]; i++)
		{
			int t;
			if(s[i] == 'T') t = 10;
			else if(s[i] == 'J') t = 11;
			else if(s[i] == 'Q') t = 12;
			else if(s[i] == 'K') t = 13;
			else if(s[i] == 'A') t = 14;
			else if(s[i] == '2') t = 15;
			else if(s[i] == 'X') t = 16;
			else if(s[i] == 'Y') t = 17;
			else t = s[i]-'0';
			y[t]++;
		}
		
		if(x[16] == 1 && x[17] == 1) //有大小王 
		{
			printf("Yes\n");
			continue;
		}
		
		if(Win(len)) { printf("Yes\n"); continue ; } //出完的情况 
		
		if(y[16] == 1 && y[17] == 1) //有大小王 
		{
			printf("No\n");
			continue;
		}
		
		
		int bomb = -1, p;
		for(int i = 17; i >= 3; i--) //炸弹 
		{
			if(x[i] == 4)
			{
				bomb = 1;
				p = i;
				break;
			}
		}
		
		int win = 1;
		if(bomb == 1)
		{
			for(int i = 17; i > p; i--)
			{
				if(y[i] == 4)
				{
				 	win = 0; break;
				}
			}
		}
		
		if(bomb == 1 && win) { printf("Yes\n"); continue; } //有炸弹且最大 
		else if(!win) { printf("No\n"); continue ;} //有炸弹,但输了。 
		
		for(int i = 3; i <= 17; i++) if(y[i] == 4) { bomb = 2; break; }
		if(bomb == 2) { printf("No\n"); continue ; } //对手有炸弹,我没有。
		
		
		win = 1;
		int Tri = -1;
		for(int i = 17; i >= 3; i--) //三个 
		{
			if(x[i] == 3)
			{
				Tri = 1;
				p = i;
				break;
			}
		}
		
		if(Tri == 1)
		{
			for(int i = 17; i > p; i--)
			{
				if(y[i] == 3)
				{
					Tri = 0;
					break;
				}
			}
		}
		
		if(Tri == 1) { printf("Yes\n"); continue ;}
		else if(Tri == 0) win = 0;
		
		
		int Dou = -1;
		for(int i = 17; i >= 3; i--) //两个 
		{
			if(x[i] == 2)
			{
				Dou = 1;
				p = i;
				break;
			}
		}
		
		if(Dou == 1)
		{
			for(int i = 17; i > p; i--)
			{
				if(y[i] == 2 || y[i] == 3)
				{
					Dou = 0;
					break;
				}
			}
		}
		
		if(Dou == 1) { printf("Yes\n"); continue ; }
		else if(Dou == 0) win = 0;
		
		int solo = -1;
		for(int i = 17; i >= 3; i--) //一个 
		{
			if(x[i] == 1)
			{
				solo = 1;
				p = i; 
				break;
			}
		}
		
		if(solo == 1)
		{
			if(win == 0) win = 1;
			for(int i = 17; i > p; i--)
			{
				if(y[i] == 1 || y[i] == 2 || y[i] == 3) { win = 0; break; }
			}
		}
		
		if(win == 1) printf("Yes\n");
		else if(win == 0) printf("No\n");
	}
	return 0;
}
jackjohnny 说:
2021年6月17日 23:04

Very nice article, I enjoyed reading your post, very nice share, I want to twit this to my followers. Thanks!. 먹튀검증

jackjohnny 说:
2021年6月26日 22:03

Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. 스포츠토토

jackjohnny 说:
2021年6月29日 18:45

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. Indiase visa

jackjohnny 说:
2021年7月05日 19:20

I found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious... สล็อต

jackjohnny 说:
2021年7月11日 20:16

If you are looking for more information about flat rate locksmith Las Vegas check that right away. 토토사이트


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter