计蒜之道(阿里的新游戏)第一题 解题报告

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

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

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

样例对应的棋盘如下:

输入格式

输入第一行两个整数 n,m(3≤n,m≤9)n,m(3 \le n, m \le 9)n,m(3n,m9)nnn 表示小红的棋子数,mmm 表示小明的棋子数。

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

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

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

输出格式

输出小红成三的线段数。

样例输入

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

样例输出

2



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class One1 {

	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		line=br.readLine();
		String [] strs=line.split(" ");
		int n=Integer.parseInt(strs[0]);
		int m=Integer.parseInt(strs[1]);
		
		Point [] p=new Point[n];
		for(int i=0;i(){
			public int compare(Point p1,Point p2){
				if(p1.xp2.x){
					return 1;
				}
				else{
					if(p1.yp2.y){
						return 1;
					}
					else{
						return 0;
					}
				}
			}
		});
		ans+=yAdd(p);
		
		Arrays.sort(p,new Comparator(){
			public int compare(Point p1,Point p2){
				if(p1.yp2.y){
					return 1;
				}
				else{
					if(p1.xp2.x){
						return 1;
					}
					else{
						return 0;
					}
				}
			}
		});
		
		ans+=xAdd(p);
		System.out.println(ans);
	}
	
	public static int xAdd(Point [] p){
		int ans=0;
		for(int i=2;i


你可能感兴趣的:(计蒜客,java,游戏,计蒜之道)