正方形个数
import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNextInt()){ int n = in.nextInt(); Point[] yp = new Point[n]; for(int i=0; i<n; i++){ yp[i] = new Point(in.nextInt(), in.nextInt()); } Point[] sp = new Point[4]; System.out.println(n<4?0:findRec(yp, sp, 0, 0, 0)); } }
public static int findRec(Point[] yp, Point[] sp, int i, int c, int f){
if(c == 4) return isRec(sp) + f;
if(i >= yp.length) return f;
int wi = findRec(yp, sp, i+1, c, f);
sp[c] = yp[i];
int yi = findRec(yp, sp, i+1, c+1, f);
sp[c] = null;
return wi+yi;
}
public static int isRec(Point[] p){
Point[] p1 = new Point[2];
Point[] p2 = new Point[2];
p1[0] = p[0];
for(int i=1; i<p.length; i++){
p1[1] = p[i];
int k = 0;
for(int j=1; j<p.length; j++){
if(j==i) continue;
p2[k++] = p[j];
}
if((p1[1].x-p1[0].x)*(p2[1].x-p2[0].x)+(p1[1].y-p1[0].y)*(p2[1].y-p2[0].y)==0&&
(p1[1].x+p1[0].x)==(p2[1].x+p2[0].x)&&
(p1[1].y+p1[0].y)==(p2[1].y+p2[0].y)&&
Math.pow(p1[1].x-p1[0].x, 2)+Math.pow(p1[1].y-p1[0].y, 2)==
Math.pow(p2[1].x-p2[0].x, 2)+Math.pow(p2[1].y-p2[0].y, 2)){
return 1;
}
}
return 0;
}
public static class Point{
int x;
int y;
Point(int x, int y){
this.x = x;
this.y = y;
}
}
}