2017年计蒜客初赛第一场 第一题 阿里的新游戏

这里写图片描述这里写图片描述
这里写图片描述
题解:
此题用一个二维数组来模拟局面,模拟棋盘的坐标,通过输入小红旗子和小黑旗子来在二维数组中确定旗子的位置, 此棋盘一共只有 16条直线,所以只要确定 放棋盘中旗子的位置别出现混乱就行了


import java.util.Scanner;

public class A阿里的新游戏 {
    int count = 0;
    int arrays[][] = { 
            {2,0,0,2,0,0,2},
            {0,2,0,2,0,2,0},
            {0,0,2,2,2,0,0},
            {2,2,2,0,2,2,2},
            {0,0,2,2,2,0,0},
            {0,2,0,2,0,2,0},
            {2,0,0,2,0,0,2}
    }; //棋盘对应位置, 0表示不可放旗子, 2 表示可以放旗子,1表示为小红的旗子, 3 为小黑的旗子
    public static void main(String[] args) {
        A阿里的新游戏 obj = new A阿里的新游戏();
        obj.init();
    }

    private void init() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();
        for(int i = 0; i < n; i++) {
            int x = input.nextInt();
            int y = input.nextInt();
            int x1 = 0;
            int y1 = 0;
            if (y >= 0) {
                y1 = 3 - Math.abs(y);
            } else {
                y1 = 3 + Math.abs(y);
            }
            if (x >= 0) {
                x1 = 3 + Math.abs(x);
            } else {
                x1 = 3 - Math.abs(x);
            }
            if (arrays[y1][x1] != 0) {
                arrays[y1][x1] = 1;
                }
        }
        for(int i = 0; i < m; i++) {
            int x = input.nextInt();
            int y = input.nextInt();
            int x1;
            int y1;
            if (y >= 0) {
                y1 = 3 - Math.abs(y);
            } else {
                y1 = 3 + Math.abs(y);
            }
            if (x >= 0) {
                x1 = 3 + Math.abs(x);
            } else {
                x1 = 3 - Math.abs(x);
            }
            if (arrays[y1][x1] != 0) {
            arrays[y1][x1] = 3;
            }
        }
        check();
    //  printf(); //输出棋盘
        System.out.println(count);
    }

    private void printf() {
        for (int i = 0; i < arrays.length; i++) {
            for (int j = 0; j < arrays[0].length; j++) {
                System.out.print(arrays[i][j]+" ");
            }
            System.out.println();
        }
    }

    private void check() {
        count  += check(arrays[0][0],arrays[0][3],arrays[0][6]);
        count  += check(arrays[1][1],arrays[1][3],arrays[1][5]);
        count  += check(arrays[2][2],arrays[2][3],arrays[2][4]);
        count  += check(arrays[3][0],arrays[3][1],arrays[3][2]);
        count  += check(arrays[3][4],arrays[3][5],arrays[3][6]);
        count  += check(arrays[4][2],arrays[4][3],arrays[4][4]);
        count  += check(arrays[5][1],arrays[5][3],arrays[5][5]);
        count  += check(arrays[6][0],arrays[6][3],arrays[6][6]);  //此8条是横轴 的直线

        count  += check(arrays[0][0],arrays[3][0],arrays[6][0]);
        count  += check(arrays[1][1],arrays[3][1],arrays[5][1]);
        count  += check(arrays[2][2],arrays[3][2],arrays[4][2]);
        count  += check(arrays[0][3],arrays[1][3],arrays[2][3]);
        count  += check(arrays[4][3],arrays[5][3],arrays[6][3]);
        count  += check(arrays[2][4],arrays[3][4],arrays[4][4]);
        count  += check(arrays[1][5],arrays[3][5],arrays[5][5]);
        count  += check(arrays[0][6],arrays[3][6],arrays[6][6]);  //此8条是纵轴 直线
    }
    public int check(int a,int b, int c){
        if (a == b && b == c && a == 1) {
            return 1;
        } 
        return 0;
    }

}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值