That is, 13 cards are given. Ask which cards can be added.
Hu Pai has the following situations:
1. One pair + four groups of three identical cards or shunzi. Only M, S, and P can constitute a subfolder. Brands like East and West are not good.
2. Seven different pairs.
3. 1 m, 9 m, 1 P, 9 P, 1 s, 9 s, 1C, 2c, 3c, 4C, 5C, 6C, 7c. each of these 13 cards has only these 13 cards. There must be two. The other one.
The first is to enumerate 18 + 7 = 34 cards and add 14 cards to determine the cards.
Hu Pai's judgment is as follows.
In the first case, enumerate each pair. Then, search for three identical or shunzi images in sequence. If there are three identical sheets, they constitute three identical sheets. If you don't have it, you can see whether it can make up with the following. Be sure to search in ascending order. 1c ''' 7C can only make up three identical images. Then determine if exactly four groups are found.
In the second case, the number of each card is either 0 or 2, which must be seven different pairs.
The third case is to make the number of the 13 cards not equal to 0, and the number of other cards is 0;
#include <cstdio>#include <iostream>#include <vector>#include <algorithm>#include <cstring>using namespace std;int T, ans[300], sub, p[100], v[100];char c, str[10];const char * mah[] ={ "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"};int ver[20] = { 0,8,9,17,18,26,27,28,29,30,31,32,33};int convert(char * s){ for(int i = 0; i < 34; i ++){ if(strcmp(s,mah[i]) == 0) return i; }return -1;}// return falsebool three(int x){ int ret = 0; int tmp[35] ; for(int i = 0; i < 34; i ++) tmp[i] = p[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 realcheck(){ for(int i = 0; i < 34; i ++){ if(p[i] >= 2){ p[i] -= 2; if(three(0)){ p[i] += 2; return true; }p[i] += 2; } } return false;}bool eyes(){ for(int i = 0; i < 34; i ++){ if(p[i] != 2 && p[i] != 0) return false; } return true;}bool spe(){ for(int j = 0; j < 7; j ++) if(p[j + 27] == 0) return false; for(int i = 0; i <= 18; i += 9){ if(p[i] == 0 || p[i + 8] == 0) return false; for(int j = 1; j < 8; j ++){ if(p[i + j] != 0) return false; } } return true;}bool judge(){ if(realcheck() || eyes() || spe()){ return true; }return false;}int main(){ scanf("%d", & T); while(T --){ for(int i = 0; i < 13; i ++){ scanf("%s", str); v[i] = convert(str); } memset(p, 0, sizeof(p)); for(int i = 0; i < 13; i ++){ p[v[i]] ++; } sub = 0; for(int i = 0; i < 34; i ++){ if(p[i] < 4){ p[i] ++; if(judge()){ ans[sub ++] = i; } p[i] --; } } if(sub >= 1){ printf("%d", sub); for(int i = 0; i < sub; i ++){ printf(" %s", mah[ans[i]]); }printf("\n"); }else{ printf("Nooten\n"); } }}