阿里九游开放平台近日上架了一款新的益智类游戏——成三棋。成三棋是我国非常古老的一个双人棋类游戏,其棋盘如下图所示:
成三棋的棋盘上有很多条线段,只能在线段交叉点上放入棋子。我们可以用坐标系来描述棋盘:
如果一条线段上的三个交叉点都被同一玩家的棋子占据的话,则称这条线段被该玩家 成三。现在,小红和小明两人在游戏平台上下棋,其中小红的棋子是黑色的。请你帮小红计算他成三的线段数。
样例对应的棋盘如下:
输入格式
输入第一行两个整数 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);
}
}