WEEK 6 limited time simulation to master the magic of Dongdong II

topic:

Dongdong has A × B playing cards. Each playing card has a size (integer, a, range 0 to A-1) and a suit (integer, b), range 0 to B-1.

Playing cards are different and unique, which means that no two cards are the same size and suit.

"One hand card" means that you have 5 different cards in your hand. These 5 cards are not in the order of who is in front and who are in the back. They can form a card type. We have defined 9 types of cards. The following are the rules of 9 types of cards. We use "lower number first" to match the cards. That is, the first card rule that this "one-hand card" meets from top to bottom is its "Card number" (an integer from 1 to 9):

1. Straight flush: Rule 5 and rule 4 are met at the same time.
2. Bomb: 5 of 4 cards are equal in size.
3. Three belts: 3 of 5 cards are equal in size and 2 more The size of the cards is also equal.
4. Flush: 5 cards of the same suit.
5. Straight: 5 cards of the size x, x + 1, x + 2, x + 3, x + 4.
6. Three cards: 5 cards, 3 of which are equal in size.
7. Two pairs: 5 cards, 2 of which are equal in size, and 2 of the other 3 cards are equal in size.
8. One pair : Two of the five cards are the same size.
9. Can't afford it: This hand does not satisfy any of the above card types.

Now, Dongdong takes 2 cards from the A × B playing cards! They are (a1, b1) and (a2, b2). (Where a is the size and b is the suit)

Now we have to randomly take 3 more cards from the remaining cards! Form a hand! !

In fact, in addition to playing codes, Dongdong is still a magician in his spare time. Now he wants to predict the possibility of his future, that is, the possibility of the "first hand" he will get. , Belonging to 1 to 9) "to indicate the hand type of this hand, then he has 9 possibilities in the future, but the number of each possible scheme is different.

Now, Dong Dong ’s eye of Agomo is gone. You need to help him count the number of options for each of the 9 types.

Input format

Line 1 contains integers A and B (5 ≤ A ≤ 25, 1 ≤ B ≤ 4).
Line 2 contains integers a1, b1, a2, b2 (0 ≤ a1, a2 ≤ A-1, 0 ≤ b1 , b2 ≤ B-1, (a1, b1) ≠ (a2, b2)).

Output format

Output a line, this line has 9 integers, each integer represents the number of 9 card types (in order of card number from small to large)

Sample

Sample Input1

5 2
1 0 3 1
1

Sample Output1

0 0 0 0 8 0 12 36 0

Sample Input2

25 4
0 0 24 3
1

Sample Output2

0 2 18 0 0 644 1656 36432 113344

Ideas

According to the title, it is necessary to combine the two cards that have been obtained with the remaining cards that meet the conditions to form five cards, then identify the card type number, and then record how many different card types are possible. The method here is to put the eligible cards in addition to the two cards already in hand into an array, and then perform dfs on the array to traverse all the card combinations. If the selected card is five when 2 is selected, the card type is judged, the number of records of the corresponding card type is +1, and the record array is finally output.

Reflection:

The point of this question is to traverse all the cards. I didn't consider dfs during the class (because I didn't have a good grasp). I always tried to use bfs. After the exchange after class, dfs was chosen.

Code:

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct poker
{
	int val, col;
};
int a, b, f1, v1, f2, v2, flag;
int sum[9];
poker note[105];
vector<poker> arr;

bool cmp10(poker a,poker b)
{
	return a.val < b.val;
}

void judge()
{
	vector<poker> tp = arr;
	sort(tp.begin(), tp.end(), cmp10);
	bool th = false, sz = false;
	int yz = 0, hs = 0;
	for (int i = 0; i < 4; i++)
	{
		if (tp[i].col == tp[i + 1].col)
			hs++;
		if (tp[i].val + 1 == tp[i + 1].val)
			yz++;
	}
	if (yz == 4)
		sz = true;
	if (hs == 4)
		th = true;
	if (sz == true && th == true)
	{
		sum[0]++;
		return;
	}
	if (tp[0].val==tp[3].val||tp[1].val==tp[4].val)
	{
		sum[1]++;
		return;
	}
	if ((tp[0].val==tp[2].val&&tp[3].val==tp[4].val)
		||(tp[0].val==tp[1].val&&tp[2].val==tp[4].val))
	{
		sum[2]++;
		return;
	}
	if (th == true)
	{
		sum[3]++;
		return;
	}
	if (sz == true)
	{
		sum[4]++;
		return;
	}
	if (tp[0].val == tp[2].val || tp[1].val == tp[3].val || tp[2].val == tp[4].val)
	{
		sum[5]++;
		return;
	}
	if ((tp[0].val == tp[1].val && (tp[2].val == tp[3].val || tp[3].val == tp[4].val))
		|| (tp[1].val == tp[2].val&&tp[3].val == tp[4].val))
	{
		sum[6]++; 
		return;
	}
	if (tp[0].val == tp[1].val || tp[1].val == tp[2].val
		|| tp[2].val == tp[3].val || tp[3].val == tp[4].val)
	{
		sum[7]++;
		return;
	}
	sum[8]++;
	return;
}

void dfs(int i)
{
	if (arr.size() == 5)
	{
		judge();
		return;
	}
	if (i < flag)
	{
		dfs(i + 1);
		arr.push_back(note[i]);
		dfs(i + 1);
		arr.pop_back();
	}
}

int main()
{
	scanf_s("%d%d%d%d%d%d", &a, &b, &v1, &f1,&v2,&f2);
	for (int i = 0; i < 9; i++)
		sum[i] = 0;
	arr.push_back({ v1,f1 });
	arr.push_back({ v2,f2 });
	flag = 0;
	for (int i = 0; i < a; i++)
	{
		for (int j = 0; j < b; j++)
		{
			if ((i != v1 || j != f1) && (i != v2 || j != f2))
			{
				note[flag] = { i,j };
				flag++;
			}
		}
	}
	dfs(0);
	for (int i = 0; i < 8; i++)
		cout << sum[i] << ' ';
	cout << sum[8] << endl;
    return 0; 
}
Published 32 original articles · praised 0 · visits 677

Guess you like

Origin blog.csdn.net/qq_43814559/article/details/105254665