阿里的新游戏—计蒜客A1183

阿里九游开放平台近日上架了一款新的益智类游戏——成三棋。成三棋是我国非常古老的一个双人棋类游戏,其棋盘如下图所示:

成三棋的棋盘上有很多条线段,只能在线段交叉点上放入棋子。我们可以用坐标系来描述棋盘:

如果一条线段上的三个交叉点都被同一玩家的棋子占据的话,则称这条线段被该玩家 成三。现在,小红和小明两人在游戏平台上下棋,其中小红的棋子是黑色的。请你帮小红计算他成三的线段数。

样例对应的棋盘如下:

输入格式

输入第一行两个整数 n,m(3≤n,m≤9)n,m(3≤n,m≤9),nn 表示小红的棋子数,mm 表示小明的棋子数。

接下来 nn 行输入小红的棋子坐标。

接下来 mm 行输入小明的棋子坐标。

输入保证坐标合法,并且棋子之间不重合。

输出格式

输出小红成三的线段数。

样例输入 复制

6 3
-1 0
-2 0
-3 0
-1 -1
-1 1
1 0
0 2
0 3
2 2

样例输出 复制

2

主要解决思想就是用一个二维数组保存下的位置  然后标记

如图

 

然后正常写代码就行

import java.util.Scanner;

/**
 * Created by taoqianlixiaolang on 2019/4/6.
 */
public class shangchang {
    public static void main(String[]args) {

        int mount=0;

        Scanner sc=new Scanner(System.in);

        int x=sc.nextInt();
        int y=sc.nextInt();

        boolean [][] a=new boolean[7][7];

        for (int i=0;i<x;i++){
            int x1=sc.nextInt()+3;
            int y1=sc.nextInt()+3;

            a[x1][y1]=true;
        }
        for (int i=0;i<y;i++){
            int x2=sc.nextInt();
            int y2=sc.nextInt();
        }

        if(a[0][0]==true&&a[3][0]==true&&a[6][0]==true)mount++;
        if(a[6][0]==true&&a[6][3]==true&&a[6][6]==true) mount++;
        if(a[0][6]==true&&a[3][6]==true&&a[6][6]==true) mount++;
        if(a[0][0]==true&&a[0][3]==true&&a[0][6]==true) mount++;
        //最外部正方形

        if(a[1][1]==true&&a[3][1]==true&&a[5][1]==true)mount++;
        if(a[5][1]==true&&a[5][3]==true&&a[5][5]==true)mount++;
        if(a[1][5]==true&&a[3][5]==true&&a[5][5]==true)mount++;
        if(a[1][1]==true&&a[2][3]==true&&a[2][4]==true)mount++;
        //中间正方形

        if(a[2][2]==true&&a[3][2]==true&&a[4][2]==true)mount++;
        if(a[4][2]==true&&a[4][3]==true&&a[4][4]==true)mount++;
        if(a[2][4]==true&&a[3][4]==true&&a[4][4]==true)mount++;
        if(a[2][2]==true&&a[2][3]==true&&a[2][4]==true)mount++;
        //内部正方形

        if(a[3][0]==true&&a[3][1]==true&&a[3][2]==true)mount++;
        if(a[4][3]==true&&a[5][3]==true&&a[6][3]==true)mount++;
        if(a[3][4]==true&&a[3][5]==true&&a[3][6]==true)mount++;
        if(a[0][3]==true&&a[1][3]==true&&a[2][3]==true)mount++;
        System.out.println(mount);
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值