hdu 4431 模拟

来源:互联网 发布:windows ad域管理工具 编辑:程序博客网 时间:2024/06/05 05:37

传送门

十三幺,对子特判。

摸一张牌,枚举34次,看这副牌能不能胡。再枚举对子,在此基础上dfs。

滚筒和顺子就-3,回溯,看最后牌打满14张没有。

//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define s_1(x) scanf("%d",&x)#define s_2(x,y) scanf("%d%d",&x,&y)#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)#define S_1(x) scan_d(x)#define S_2(x,y) scan_d(x),scan_d(y)#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define fOR(n,x,i) for(int i=n;i>=x;i--)#define fOr(n,x,i) for(int i=n;i>x;i--)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long long#define mp make_pair#define pb push_backtypedef long long LL;typedef pair <int, int> ii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=4e3+10;const int maxx=4e5+10;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;char *xx[]={"1m","2m","3m","4m","5m","6m","7m","8m","9m","1s","2s","3s","4s","5s","6s","7s","8s","9s", "1p","2p","3p","4p","5p","6p","7p","8p","9p","1c", "2c", "3c", "4c", "5c", "6c","7c"};//stccmp(s,a)==0int a[15],c[50],tot;int ans[50],flag=0,ff=0;int get_id(char *s){    for(int i=0;i<49;i++)    {        if(strcmp(xx[i],s)==0)        {            return i;        }    }    return -1;}int get_xx(int xxx){    if(xxx==2)        return 1;    return 0;}int is_13(){    int cnt=0,xxx=0;    for(int i=27;i<=33;i++)        if(c[i])        {            if(get_xx(c[i])) xxx++;            cnt++;        }    if(c[0])    {        cnt++;        if(get_xx(c[0])) xxx++;    }    if(c[8])    {        cnt++;        if(get_xx(c[8])) xxx++;    }    if(c[9])    {        cnt++;        if(get_xx(c[9])) xxx++;    }    if(c[17])    {        cnt++;        if(get_xx(c[17])) xxx++;    }    if(c[18])    {        cnt++;        if(get_xx(c[18])) xxx++;    }    if(c[26])    {        cnt++;        if(get_xx(c[26])) xxx++;    }    if(cnt==13&&xxx)        return 1;    return 0;}void dfs(int x){    if(x==14)    {        ff=1;        return ;    }    for(int i=0;i<34;i++)    {        int z=0;        if(c[i]>=3)        {            z++;            c[i]-=3;            dfs(x+3);            c[i]+=3;        }        if(c[i]&&c[i+1]&&c[i+2]&&((0<=i&&i<=6)||(9<=i&&i<=15)||                        (18<=i&&i<=24)))        {            z++;            c[i]--;c[i+1]--;c[i+2]--;            dfs(x+3);            c[i]++;c[i+1]++;c[i+2]++;        }        if(!z&&c[i]) return ;//剪枝        if(c[i]) break;    }}int fi(){    int cnt=0;    if(is_13())        return 1;    for(int i=0;i<34;i++)        if(c[i]==2) cnt++;    if(cnt==7)        return 1;    for(int i=0;i<34;i++)    {        ff=0;        if(c[i]>=2)        {            c[i]-=2;            dfs(2);            if(ff)                return 1;            c[i]+=2;        }    }    return 0;}void judge(){    for(int i=0;i<34;i++)    {        me(c,0);        int f=0;        c[i]++;        for(int j=0;j<=12;j++)        {            c[a[j]]++;            if(c[a[j]]>4)            {                f=1;                break;            }        }        if(f)            continue;        else        {            if(fi())            {                ans[tot++]=i;                flag=1;            }        }    }}void solve(){    char op[10];    tot=0;    flag=0;    FOR(0,12,i)    {        scanf("%s",op);        a[i]=get_id(op);    }    judge();    if(flag)    {        printf("%d",tot);        FOr(0,tot,i)        {            printf(" %s",xx[ans[i]]);        }        puts("");    }    else puts("Nooten");}int main(){    //freopen( "in.txt" , "r" , stdin );    //freopen( "data.txt" , "w" , stdout );    int t=1;    s_1(t);    for(int cas=1;cas<=t;cas++)    {        //printf("Case %d:\n",cas);        solve();    }}