专栏首页机器学习入门POJ 刷题系列:2993. Emag eht htiw Em Pleh

POJ 刷题系列:2993. Emag eht htiw Em Pleh

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014688145/article/details/78866516

POJ 刷题系列:2993. Emag eht htiw Em Pleh

传送门:2993. Emag eht htiw Em Pleh

题意:

与2996相反,给出所有棋子的坐标关系,可视化board。详见2996. Help Me with the Game

思路: 先初始化board,接着把white和black的坐标提取出来,唯一区别对待的是Pawn,接着找到坐标和board的映射关系即可。

代码如下:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.StringTokenizer;

public class Main{

    String INPUT = "./data/judge/201712/P2993.txt";

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    char[][] board;
    int row = 17;
    int col = 33;

    void init() {
        board = new char[row][col];
        for (int i = 0; i < row; i += 2) {
            String line = "+---+---+---+---+---+---+---+---+";
            for (int j = 0; j < col; ++j) {
                board[i][j] = line.charAt(j);
            }
        }

        for (int i = 3; i < row; i += 4) {
            String line = "|:::|...|:::|...|:::|...|:::|...|";
            for (int j = 0; j < col; ++j) {
                board[i][j] = line.charAt(j);
            }
        }

        for (int i = 1; i < row; i += 4) {
            String line = "|...|:::|...|:::|...|:::|...|:::|";
            for (int j = 0; j < col; ++j) {
                board[i][j] = line.charAt(j);
            }
        }
    }

    void print() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < row; ++i) {
            for (int j = 0; j < col; ++j) {
                sb.append(board[i][j] + (j + 1 == col ? "\n" : ""));
            }
        }

        out.print(sb.toString());
    }

    void chessOnBoard(String[] pos, boolean white) {
        int n = pos.length;
        for (int i = 0; i < n; ++i) {
            char c = pos[i].charAt(0);
            if (notPawn(c)) {
                int col = pos[i].charAt(1) - 'a';
                int row = 8 - (pos[i].charAt(2) - '0');
                int nr = 2 * row + 1;
                int nc = 4 * col + 2;
                if (white)
                    board[nr][nc] = c;
                else board[nr][nc] = (char) (c - 'A' + 'a');
            }
            else {
                int col = pos[i].charAt(0) - 'a';
                int row = 8 - (pos[i].charAt(1) - '0');
                int nr = 2 * row + 1;
                int nc = 4 * col + 2;
                if (white)
                    board[nr][nc] = 'P';
                else board[nr][nc] = 'p';
            }
        }
    }

    boolean notPawn(char c) {
        if (c == 'K' || c == 'Q' || c == 'R' || c == 'B' || c== 'N') return true;
        return false;
    }


    void read() {
        ns();
        String white = ns();
        ns();
        String black = ns();

        init();
        chessOnBoard(white.split(","), true);
        chessOnBoard(black.split(","), false);
        print();
    }


    FastScanner in;
    PrintWriter out;

    void run() throws IOException {
        boolean oj;
        try {
            oj = ! System.getProperty("user.dir").equals("F:\\oxygen_workspace\\Algorithm");
        } catch (Exception e) {
            oj = System.getProperty("ONLINE_JUDGE") != null;
        }

        InputStream is = oj ? System.in : new FileInputStream(new File(INPUT));
        in = new FastScanner(is);
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        read();
        out.flush();
        if (!oj){
            System.out.println("[" + (System.currentTimeMillis() - s) + "ms]");
        }
    }

    public boolean more(){
        return in.hasNext();
    }

    public int ni(){
        return in.nextInt();
    }

    public long nl(){
        return in.nextLong();
    }

    public double nd(){
        return in.nextDouble();
    }

    public String ns(){
        return in.nextString();
    }

    public char nc(){
        return in.nextChar();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        boolean hasNext;

        public FastScanner(InputStream is) throws IOException {
            br = new BufferedReader(new InputStreamReader(is));
            hasNext = true;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    hasNext = false;
                    return "##";
                }
            }
            return st.nextToken();
        }

        String next = null;
        public boolean hasNext(){
            next = nextToken();
            return hasNext;
        }

        public int nextInt() {
            if (next == null){
                hasNext();
            }
            String more = next;
            next = null;
            return Integer.parseInt(more);
        }

        public long nextLong() {
            if (next == null){
                hasNext();
            }
            String more = next;
            next = null;
            return Long.parseLong(more);
        }

        public double nextDouble() {
            if (next == null){
                hasNext();
            }
            String more = next;
            next = null;
            return Double.parseDouble(more);
        }

        public String nextString(){
            if (next == null){
                hasNext();
            }
            String more = next;
            next = null;
            return more;
        }

        public char nextChar(){
            if (next == null){
                hasNext();
            }
            String more = next;
            next = null;
            return more.charAt(0);
        }
    }

    static class D{

        public static void pp(int[][] board, int row, int col) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < row; ++i) {
                for (int j = 0; j < col; ++j) {
                    sb.append(board[i][j] + (j + 1 == col ? "\n" : " "));
                }
            }
            System.out.println(sb.toString());
        }

        public static void pp(char[][] board, int row, int col) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < row; ++i) {
                for (int j = 0; j < col; ++j) {
                    sb.append(board[i][j] + (j + 1 == col ? "\n" : " "));
                }
            }
            System.out.println(sb.toString());
        }
    }

    static class ArrayUtils {

        public static void fill(int[][] f, int value) {
            for (int i = 0; i < f.length; ++i) {
                Arrays.fill(f[i], value);
            }
        }

        public static void fill(int[][][] f, int value) {
            for (int i = 0; i < f.length; ++i) {
                fill(f[i], value);
            }
        }

        public static void fill(int[][][][] f, int value) {
            for (int i = 0; i < f.length; ++i) {
                fill(f[i], value);
            }
        }
    }

    static class Num{
        public static <K> void inc(Map<K, Integer> mem, K k) {
            if (!mem.containsKey(k)) mem.put(k, 0);
            mem.put(k, mem.get(k) + 1);
        }
    }
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • POJ 刷题系列:2002. Squares

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • POJ 刷题系列:1789. Truck History

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • 挑战程序竞赛系列(59):4.6树上的分治法(2)

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • 洛谷P2770 航空路线问题(费用流)

    为了满足流量的限制,肯定会想到拆点,把每个点拆为两个,连流量为$1$,费用为$1$的边

    attack
  • 挑战程序竞赛系列(82):4.3 LCA(2)

    挑战程序竞赛系列(82):4.3 LCA(2) 传送门:POJ 1986: Distance Queries 题意: LCA距离:快速查询树中任意两个节点间...

    用户1147447
  • C++初始化

    Qt君
  • 挑战程序竞赛系列(59):4.6树上的分治法(2)

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • POJ 刷题系列:1789. Truck History

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • POJ 刷题系列:2002. Squares

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • 4.7后缀数组

    第一次接触后缀数组,采用《挑战》P378的后缀算法,时间复杂度为O(nlog2n)O(n\log^2n),基本思想如下:

    用户1147447

扫码关注云+社区

领取腾讯云代金券