二维数组,因为问的是小红成三数量,所以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;
}
}