//第六届蓝桥杯软件类省赛真题-C-B-7_牌型种数.cpp
/*
【题目】
牌型种数
小明被劫持到X赌城,被迫与其他3人玩牌。
一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张。
这时,小明脑子里突然冒出一个问题:
如果不考虑花色,只考虑点数,也不考虑自己得到的牌的先后顺序,
自己手里能拿到的初始牌型组合一共有多少种呢?
请填写该整数,不要填写任何多余的内容或说明文字。
*/
/*【解题思路】
解法一:根据题意可得小明的13张初始牌型组合中至少含有4种牌型,最多含有13种牌型,
然后可以根据这点进行暴力枚举了
解法二:将暴力枚举算法转化为递归解决,简化代码量
答案:
2872
*/
#include<iostream>
using namespace std;
int main()
{
int count = 0;
int sum = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++){
if(a+b+c+d == 13)//如果4种牌型(a,b,c,d表示这4种牌型)的数量加起来的种数为13则满足题意条件
{
count++;
cout<<"a_"<<a<<" b_"<<b<<" c_"<<c<<" d_"<<d<<endl;
}
}
cout<<"count_1 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++){
if(a+b+c+d+e == 13)//如果5种牌型(a,b,c,d,e表示这5种牌型)的数量加起来的种数为13则满足题意条件
{
count++;
}
}
cout<<"count_2 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++){
if(a+b+c+d+e+f == 13)
{
count++;
}
}
cout<<"count_3 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++){
if(a+b+c+d+e+f+g == 13)
{
count++;
}
}
cout<<"count_4 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++)
for(int h=1;h<=4;h++){
if(a+b+c+d+e+f+g+h == 13)
{
count++;
}
}
cout<<"count_5 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++)
for(int h=1;h<=4;h++)
for(int i=1;i<=4;i++){
if(a+b+c+d+e+f+g+h+i == 13)
{
count++;
}
}
cout<<"count_6 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++)
for(int h=1;h<=4;h++)
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++){
if(a+b+c+d+e+f+g+h+i+j == 13)
{
count++;
}
}
cout<<"count_7 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++)
for(int h=1;h<=4;h++)
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++)
for(int k=1;k<=4;k++){
if(a+b+c+d+e+f+g+h+i+j+k == 13)
{
count++;
}
}
cout<<"count_8 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++)
for(int h=1;h<=4;h++)
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++)
for(int k=1;k<=4;k++)
for(int l=1;l<=4;l++){
if(a+b+c+d+e+f+g+h+i+j+k+l == 13)
{
count++;
}
}
cout<<"count_9 = "<<count<<endl;
sum += count;
count = 0;
for(int a=1;a<=4;a++)
for(int b=1;b<=4;b++)
for(int c=1;c<=4;c++)
for(int d=1;d<=4;d++)
for(int e=1;e<=4;e++)
for(int f=1;f<=4;f++)
for(int g=1;g<=4;g++)
for(int h=1;h<=4;h++)
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++)
for(int k=1;k<=4;k++)
for(int l=1;l<=4;l++)
for(int m=1;m<=4;m++){
if(a+b+c+d+e+f+g+h+i+j+k+l+m == 13)
{
count++;
}
}
cout<<"count_10 = "<<count<<endl;
sum += count;
cout<<"自己手里能拿到的初始牌型组合一共有"<<sum<<"种";
return 0;
}
第六届蓝桥杯软件类省赛真题-C-B-7_牌型种数
最新推荐文章于 2023-03-17 17:11:53 发布