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

题意:就是给了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[];
bool judge4X3()
{
int ret=;
int tmp[];
for(int i=;i<;i++)tmp[i]=cnt[i]; for(int i=;i<=;i+=)
for(int j=;j<;j++)
{
if(tmp[i+j]>=) //相同的
{
tmp[i+j]-=;
ret++;
}
while(j+< && tmp[i+j] && tmp[i+j+] &&tmp[i+j+]) //不同的
{
tmp[i+j]--;
tmp[i+j+]--;
tmp[i+j+]--;
ret++;
}
}
for(int j=;j<;j++) //东西南北
{
if(tmp[+j]>=)
{
tmp[+j]-=;
ret++;
}
}
if(ret==)return true;
return false;
}
bool judge1() //判断对子和4个三连的情况
{
for(int i=;i<;i++)
{
if(cnt[i]>=)
{
cnt[i]-=;//枚举对子
if(judge4X3())
{
cnt[i]+=;
return true;
}
cnt[i]+=;
}
}
return false;
}
bool judge2() //判断全是对子的情况
{
for(int i=;i<;i++)
{
if(cnt[i]!= && cnt[i]!=)
return false;
}
return true;
}
bool judge3() //判断全部不相同的情况
{
for(int j=;j<;j++)
if(cnt[j+]==)
return false;
for(int i=;i<=;i+=)
{
if(cnt[i]== || cnt[i+]==)return false;
for(int j=;j<;j++) //不能再出现其他的牌
if(cnt[i+j]!=)
return false;
}
return true;
}
bool judge()
{
if(judge1() || judge2() || judge3())return true;
return false;
}
int main()
{
int T;
char str[];
scanf("%d",&T);
int ans[],tol;
while(T--)
{
memset(cnt,,sizeof(cnt));
for(int i=;i<;i++)
{
scanf("%s",&str);
int t=str[]-'';
if(str[]=='m')t+=;
else if(str[]=='s')t+=;
else if(str[]=='p')t+=;
else t+=;
cnt[t]++;
} //将麻将排个序
tol=;
for(int i=;i<;i++)
{
cnt[i]++;
if(cnt[i]<= && judge()) //麻将个数不能大于4,
ans[tol++]=i; //符合条件
cnt[i]--;
}
if(tol==)printf("Nooten\n");
else
{
printf("%d",tol);
for(int i=;i<tol;i++)
{
printf(" %d",(ans[i]%)+);
if(ans[i]/==)printf("m");
else if(ans[i]/==)printf("s");
else if(ans[i]/==)printf("p");
else printf("c");
}
printf("\n");
}
}
return ;
}
上一篇:河南省第十届省赛 Intelligent Parking Building


下一篇:python中Url链接编码处理(urlencode,urldecode)