Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

再次TLE……不知道还能怎么优化?

Posted by FinalLaugh at 2004-09-12 00:10:21 on Problem 1786
代码如下:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws IOException {
        System.setIn(new FileInputStream("in.txt"));
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String str;
        String dir = "SWNE";
        char[] color = {
            'C', 'D', 'S', 'H'};
        char[] value = {
            '0', '0', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q',
            'K', 'A'};
        String[] player = {
            "South player:", "West player:", "North player:", "East player:"};
        int[][] deck = new int[4][13];
        int[] p;
        int s, s1, s2, s3, s4;
        while ( (str = in.readLine()).charAt(0) != '#') {
            p = new int[4];
            s = dir.indexOf(str);
            s1 = (s + 1) % 4;
            s2 = (s + 2) % 4;
            s3 = (s + 3) % 4;
            s4 = s;
            str = in.readLine() + in.readLine();
            for (int i = 0; i < 104; i += 8) {
                deck[s1][i / 8] = change(str.charAt(i), str.charAt(i + 1));
                deck[s2][i / 8] = change(str.charAt(i + 2), str.charAt(i + 3));
                deck[s3][i / 8] = change(str.charAt(i + 4), str.charAt(i + 5));
                deck[s4][i / 8] = change(str.charAt(i + 6), str.charAt(i + 7));
            }
            for (int i = 0; i < 4; i++) {
                Arrays.sort(deck[i]);
            }
            for (int i = 0; i < 4; i++) {
                System.out.println(player[i]);
                System.out.println(
                    "+---+---+---+---+---+---+---+---+---+---+---+---+---+");
                for (int j = 0; j < 13; j++) {
                    System.out.print("|");
                    System.out.print(value[deck[i][j] % 100]);
                    System.out.print(" ");
                    System.out.print(value[deck[i][j] % 100]);
                }
                System.out.println("|");
                for (int j = 0; j < 13; j++) {
                    System.out.print("| ");
                    System.out.print(color[deck[i][j] / 100]);
                    System.out.print(" ");
                }
                System.out.println("|");
                for (int j = 0; j < 13; j++) {
                    System.out.print("|");
                    System.out.print(value[deck[i][j] % 100]);
                    System.out.print(" ");
                    System.out.print(value[deck[i][j] % 100]);
                }
                System.out.println("|");
                System.out.println(
                    "+---+---+---+---+---+---+---+---+---+---+---+---+---+");
            }
        }
        in.close();
    }

    public static int change(char c, char v) {
        int val = 0;
        if (c == 'H') {
            val = 300;
        }
        else if (c == 'S') {
            val = 200;
        }
        else if (c == 'D') {
            val = 100;

        }
        if (v <= '9') {
            val += v - '0';
        }
        else if (v == 'A') {
            val += 14;
        }
        else if (v == 'K') {
            val += 13;
        }
        else if (v == 'Q') {
            val += 12;
        }
        else if (v == 'J') {
            val += 11;
        }
        else {
            val += 10;
        }
        return val;
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator