计蒜客 阿里的新游戏

 二维数组,因为问的是小红成三数量,所以int check中判断加的是a==1,

两个chect 第一个判断是否在一条线上,另一个判断三个都是小红的棋子

import java.util.Scanner;

public class Main {
    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) {
        Main obj = new Main();
        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;
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值