题意
已有2张牌,抽取3张牌,组成“一手牌”的各种类的所有的数量
一手牌类型:
- 同花顺: 同时满足规则 5 和规则 4.
- 炸弹 : 5张牌其中有4张牌的大小相等.
- 三带二 : 5张牌其中有3张牌的大小相等,且另外2张牌的大小也相等.
- 同花 : 5张牌都是相同花色的.
- 顺子 : 5张牌的大小形如 x, x + 1, x + 2, x + 3, x + 4
- 三条: 5张牌其中有3张牌的大小相等.
- 两对: 5张牌其中有2张牌的大小相等,且另外3张牌中2张牌的大小相等.
- 一对: 5张牌其中有2张牌的大小相等.
- 要不起: 这手牌不满足上述的牌型中任意一个.
思路
求出除了已有的2张牌的所有牌的无重复组合,并针对所有组合判定手上5张牌的类型,并计数
总结
场上未做出主要原因:对求无重复的组合的方法不熟悉
代码
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int A,B,a1,b1,a2,b2;
int method[10];
pair<int,int> cards[105];
set<pair<int,int> > handcard;
int checkMethod(set<pair<int,int> > handcard){
map<int,int> temp;
int lastS=-1,lastF=-1;
bool sequences=true,flower=true;
for(auto iter=handcard.begin();iter!=handcard.end();++iter){
int nowtemp=iter->first;
int nowtemp2=iter->second;
temp[nowtemp]++;
if(lastS==-1) lastS=nowtemp;
else if(lastS+1==nowtemp) lastS=nowtemp;
else sequences=false;
if(lastF==-1) lastF=nowtemp2;
else if(lastF!=nowtemp2) flower=false;
}
int num2=0,num3=0,num4=0;
for(auto iter=temp.begin();iter!=temp.end();++iter){
int is=iter->second;
if(is==4) num4++;
else if(is==3) num3++;
else if(is==2) num2++;
}
if(sequences&&flower) return 1;
else if(num4==1) return 2;
else if(num3==1&&num2==1) return 3;
else if(flower) return 4;
else if(sequences) return 5;
else if(num3==1) return 6;
else if(num2==2) return 7;
else if(num2==1) return 8;
else return 9;
}
void solve(int k,int goal,int size){
if(goal==0){
method[checkMethod(handcard)]++;
return;
}
for(int i=k;i<size;i++){
set<pair<int,int> > temp(handcard.begin(),handcard.end());
handcard.insert(cards[i]);
solve(i+1,goal-1,size);
handcard=temp;
}
}
int main(void){
scanf("%d%d",&A,&B);
scanf("%d%d%d%d",&a1,&b1,&a2,&b2);
handcard.insert(make_pair(a1,b1));
handcard.insert(make_pair(a2,b2));
int x=0;
for(int i=0;i<A;i++){
for(int j=0;j<B;j++){
if(!(i==a1&&j==b1)&&!(i==a2&&j==b2))
cards[x++]=make_pair(i,j);
}
}
solve(0,3,x);
for(int i=1;i<=9;i++)
printf("%d ",method[i]);
printf("\n");
return 0;
}