Regular polygon

 

Problem Description
On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
 

 

Input

 

The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
 

 

Output

 

For each case, output a number means how many different regular polygon these points can make.
 

 

Sample Input

 

 
4 0 0 0 1 1 0 1 1 6 0 0 0 1 1 0 1 1 2 0 2 1
 

 

Sample Output

 

 
1 2
 

 

 

 

 

import java.util.*;
public class Main{    
    public static void main(String args[]){
        Scanner reader=new Scanner(System.in);
        while(reader.hasNext()){
            int a=reader.nextInt();
            ArrayList<A> l=new ArrayList<A>();
            //int s[][]=new int[505][505];
            int map[][]=new int[300][300];
            for(int n=0;n<a;n++){
                int x=reader.nextInt();
                int y=reader.nextInt();
                x+=100;
                y+=100;
                //System.out.println(x+" "+y);
                A aa=new A(x,y);
                l.add(aa);
                map[x][y]=1;
            }
            int sum=0;
            for(int n1=0;n1<a-1;n1++){
                for(int n2=n1+1;n2<a;n2++){
                    int x1=l.get(n1).x;
                    int y1=l.get(n1).y;
                    int x2=l.get(n2).x;
                    int y2=l.get(n2).y;
                    int xx=x1-x2;
                    int yy=y1-y2;    
                    //System.out.println(xx+" "+yy+" "+x1+" "+y1+" "+x2+" "+y2+" "+(x1+yy)+" "+(y1-xx)+" "+(x2+yy)+" "+(y2-xx));
                    if(x2+yy>=0&&x2+yy<=205&&y2-xx>=0&&y2-xx<=205&&x1+yy>=0&&x1+yy<=205&&y1-xx>=0&&y1-xx<=205&&map[x1+yy][y1-xx]==1&&map[x2+yy][y2-xx]==1){
                        sum++;
                        //System.out.println(sum);
                    }
                    if(x2-yy>=0&&x2-yy<=205&&y2+xx>=0&&y2+xx<=205&&x1-yy>=0&&x1-yy<=205&&y1+xx>=0&&y1+xx<=205&&map[x1-yy][y1+xx]==1&&map[x2-yy][y2+xx]==1){
                        sum++;
                        //System.out.println(sum);
                    }
                }                
            }
            
            System.out.println(sum/4);
        }
        
    }
    
    
}

class A{
    int x,y;
    A(int a,int b){
        x=a;y=b;
    }
}

 

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值