Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by Game 31 ( 14 years ago )
01
import java.io.BufferedReader;
02
import java.io.*;
03
 
04
public class Thirty1 {
05
    static int[] c;
06
    static char[] w = { 'A', 'B' };
07
    static char[][][][][][] dp;
08
 
09
    public static int score() {
10
        int tot = 4 * (6 + 5 + 4 + 3 + 2 + 1);
11
        for (int i = 0; i < c.length; i++)
12
            tot -= c[i] * (i + 1);
13
        return tot;
14
    }
15
 
16
    public static char go(int p) {
17
        int score = score();
18
        if (score > 31)
19
            return w[p];
20
        if (dp[c[0]][c[1]][c[2]][c[3]][c[4]][c[5]] != 0)
21
            return dp[c[0]][c[1]][c[2]][c[3]][c[4]][c[5]];
22
        char win = w[p ^ 1];
23
        for (int i = 0; i < c.length && win == w[p ^ 1]; i++)
24
            if (c[i] > 0) {
25
                c[i]--;
26
                if (go(p ^ 1) != win)
27
                    win = w[p];
28
                c[i]++;
29
            }
30
        return dp[c[0]][c[1]][c[2]][c[3]][c[4]][c[5]] = win;
31
    }
32
 
33
    public static void main(String[] args) throws Exception {
34
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
35
        while (true) {
36
            String s = in.readLine();
37
            if (s == null)
38
                break;
39
            char[] p = s.toCharArray();
40
            dp = new char[5][5][5][5][5][5];
41
            int[] count = { 4, 4, 4, 4, 4, 4 };
42
            for (int i = 0; i < p.length; i++)
43
                count[p[i] - '0' - 1]--;
44
            c = count;
45
            System.out.println(s + " " + go(p.length % 2));
46
        }
47
    }
48
}

 

Revise this Paste

Children: 58730
Your Name: Code Language: