您的位置:首页 > 其它

hdu 4431 第37届ACM/ICPC 天津赛区现场赛A题 枚举

2015-04-17 23:12 639 查看
题意:就是给了13张牌。问增加哪些牌可以胡牌。m是数字,s是条,p是筒,c是数字
胡牌有以下几种情况:
1、一个对子 + 4组 3个相同的牌或者顺子。 只有m、s、p是可以构成顺子的。东西南北这样的牌没有顺子。
2、7个不同的对子。
3、1m,9m,1p,9p,1s,9s,1c,2c,3c,4c,5c,6c,7c. 这13种牌每种都有,而且仅有这13种牌。肯定是有一种2张。其他的1张。

模拟即可,第一个对子的情况需要枚举

很麻烦的模拟,但是貌似稳银的很需要这题,所以这种难度必须要弄懂,加油!!!


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int cnt[35];
bool judge4X3()
{
int ret=0;
int tmp[35];
for(int i=0;i<34;i++)tmp[i]=cnt[i];

for(int i=0;i<=18;i+=9)
for(int j=0;j<9;j++)
{
if(tmp[i+j]>=3)   //相同的
{
tmp[i+j]-=3;
ret++;
}
while(j+2<9 && tmp[i+j] && tmp[i+j+1] &&tmp[i+j+2])   //不同的
{
tmp[i+j]--;
tmp[i+j+1]--;
tmp[i+j+2]--;
ret++;
}
}
for(int j=0;j<7;j++)    //东西南北
{
if(tmp[27+j]>=3)
{
tmp[27+j]-=3;
ret++;
}
}
if(ret==4)return true;
return false;
}
bool judge1()   //判断对子和4个三连的情况
{
for(int i=0;i<34;i++)
{
if(cnt[i]>=2)
{
cnt[i]-=2;//枚举对子
if(judge4X3())
{
cnt[i]+=2;
return true;
}
cnt[i]+=2;
}
}
return false;
}
bool judge2()   //判断全是对子的情况
{
for(int i=0;i<34;i++)
{
if(cnt[i]!=2 && cnt[i]!=0)
return false;
}
return true;
}
bool judge3()   //判断全部不相同的情况
{
for(int j=0;j<7;j++)
if(cnt[j+27]==0)
return false;
for(int i=0;i<=18;i+=9)
{
if(cnt[i]==0 || cnt[i+8]==0)return false;
for(int j=1;j<8;j++)    //不能再出现其他的牌
if(cnt[i+j]!=0)
return false;
}
return true;
}
bool judge()
{
if(judge1() || judge2() || judge3())return true;
return false;
}
int main()
{
int T;
char str[10];
scanf("%d",&T);
int ans[35],tol;
while(T--)
{
memset(cnt,0,sizeof(cnt));
for(int i=0;i<13;i++)
{
scanf("%s",&str);
int t=str[0]-'1';
if(str[1]=='m')t+=0;
else if(str[1]=='s')t+=9;
else if(str[1]=='p')t+=18;
else t+=27;
cnt[t]++;
}   //将麻将排个序
tol=0;
for(int i=0;i<34;i++)
{
cnt[i]++;
if(cnt[i]<=4 && judge())    //麻将个数不能大于4,
ans[tol++]=i;            //符合条件
cnt[i]--;
}
if(tol==0)printf("Nooten\n");
else
{
printf("%d",tol);
for(int i=0;i<tol;i++)
{
printf(" %d",(ans[i]%9)+1);
if(ans[i]/9==0)printf("m");
else if(ans[i]/9==1)printf("s");
else if(ans[i]/9==2)printf("p");
else printf("c");
}
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐