最简单的胡法,四个三张+一对
先枚举第14张牌
然后找出1对的牌之后dfs搜索三张的搭配
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
StreamTokenizer cin = new StreamTokenizer(new BufferedInputStream(System.in));
InputReader in = new InputReader(System.in) ;
PrintWriter out = new PrintWriter(System.out) ;
int k = 1 ;
String s ;
for(;;){
s = in.next() ;
if(s.equals("0")) break ;
new Task().solve(k++ , s , in, out) ; //out.flush() ;
}
out.flush() ;
}
}
class Task{
static ArrayList<String> majiang = new ArrayList<String>(Arrays.asList(
"1T" , "2T" , "3T" , "4T" , "5T" , "6T" , "7T" , "8T" , "9T" ,
"1S" , "2S" , "3S" , "4S" , "5S" , "6S" , "7S" , "8S" , "9S" ,
"1W" , "2W" , "3W" , "4W" , "5W" , "6W" , "7W" , "8W" , "9W" ,
"DONG" , "NAN" , "XI" , "BEI" ,
"ZHONG" , "FA" , "BAI" )
);
static int[] mj = new int[13] ;
static int[] num = new int[34] ;
boolean dfs(int d){
for(int i = 0 ; i < 34 ; i++){
if(num[i] >= 3){
if(d == 3) return true ;
num[i] -= 3 ;
if(dfs(d + 1)) return true ;
num[i] += 3 ;
}
}
for(int i = 0 ; i <= 24 ; i++){
if((i%9 <= 6) && num[i] >= 1 && num[i+1] >= 1 && num[i+2] >= 1){
if(d == 3) return true ;
num[i]-- ;
num[i+1]-- ;
num[i+2]-- ;
if(dfs(d + 1)) return true ;
num[i]++ ;
num[i+1]++ ;
num[i+2]++ ;
}
}
return false ;
}
boolean helper(){
for(int i = 0 ; i < 34 ; i++){
if(num[i] >= 2){
num[i] -= 2 ;
if(dfs(0)) return true ;
num[i] += 2 ;
}
}
return false ;
}
public void solve(int testcase , String s , InputReader in , PrintWriter out) throws IOException{
ArrayList<String> ans = new ArrayList<String>() ;
mj[0] = majiang.indexOf(s) ;
for(int i = 1 ; i <= 12 ; i++) mj[i] = majiang.indexOf(in.next()) ;
for(int i = 0 ; i < 34 ; i++){
Arrays.fill(num, 0) ;
for(int j = 0 ; j <= 12 ; j++) num[mj[j]]++ ;
if(num[i] >= 4) continue ;
num[i]++ ;
if(helper()) ans.add(majiang.get(i)) ;
num[i]-- ;
}
out.print("Case " + testcase + ":") ;
if(ans.size() == 0) out.println(" Not ready") ;
else{
for(String e : ans) out.print(" " + e) ;
out.println() ;
}
}
}
class InputReader{
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream){
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next(){
while(tokenizer == null || !tokenizer.hasMoreTokens()){
try{
tokenizer = new StringTokenizer(reader.readLine());
}catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}