杭电暑期多校集训—Regular polygon

Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2924    Accepted Submission(s): 685


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
 

题意:求n个点能组成的正多边形的最多个数

分析:因为输入的都是整数点,所以实际上找到组成正方形的最对个数;

已知: (x1,y1)  (x2,y2)

则:   x3=x1+(y1-y2)   y3= y1-(x1-x2)

x4=x2+(y1-y2)   y4= y2-(x1-x2)

x3=x1-(y1-y2)   y3= y1+(x1-x2)

x4=x2-(y1-y2)   y4= y2+(x1-x2)

先枚举两个点,通过以上公式得到另外两个点,再加以判断;

因为同一个正方形按照不同的顺序被枚举了四次,所以结果要除以4;


#include 
#include
#include
using namespace std;
int x[507],y[507];
int visit[207][207];
int main()
{
    int n,ans;
    while(~scanf("%d",&n))
    {
        ans=0;
        memset(visit,0,sizeof(visit));
        for(int i=0;i=0&&x[i]+dy<=200&&y[i]-dx>=0&&y[i]-dx<=200&&x[j]+dy>=0&&x[j]+dy<=200&&y[j]-dx>=0&&y[j]-dx<=200&&visit[x[i]+dy][y[i]-dx]&&visit[x[j]+dy][y[j]-dx])
                    ans++;
                if(x[i]-dy>=0&&x[i]-dy<=200&&y[i]+dx>=0&&y[i]+dx<=200&&x[j]-dy>=0&&x[j]-dy<=200&&y[j]+dx>=0&&y[j]+dx<=200&&visit[x[i]-dy][y[i]+dx]&&visit[x[j]-dy][y[j]+dx])
                    ans++;
            }
        }
        printf("%d\n",ans/4);
    }
    return 0;
}


你可能感兴趣的:(2017杭电暑期集训)