Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2546 Accepted Submission(s): 1018
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
Source
解题代码
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
struct node
{
int x,y;
}ch[505];
int vis[205][205];
int main()
{
int N;
while(scanf("%d",&N)!=EOF)
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=N;i++)
{
scanf("%d%d",&ch[i].x,&ch[i].y);
ch[i].x+=100;
ch[i].y+=100;
vis[ch[i].x][ch[i].y]=1;
}
int count1=0;
for(int i=1;i<=N;i++)
for(int j=i+1;j<=N;j++)
{
int x1=ch[i].x;
int y1=ch[i].y;
int x2=ch[j].x;
int y2=ch[j].y;
int dx=ch[i].x-ch[j].x;
int dy=ch[i].y-ch[j].y;
if(x1+dy>=0&&x1+dy<=200&&y1-dx>=0&&y1-dx<=200&&x2+dy>=0&&x2+dy<=200&&y2-dx>=0&&y2-dx<=200)
{
if(vis[x1+dy][y1-dx]==1&&vis[x2+dy][y2-dx]==1)
count1++;
}
if(x1-dy>=0&&x1-dy<=200&&y1+dx>=0&&y1+dx<=200&&x2-dy>=0&&x2-dy<=200&&y2+dx>=0&&y2+dx<=200)
{
if(vis[x1-dy][y1+dx]==1&&vis[x2-dy][y2+dx]==1)
count1++;
}
}
printf("%d\n",count1/4);
}
return 0;
}
本文介绍了一个算法问题:给定二维平面上的整数坐标点集,任务是找出这些点能构成的不同正多边形的数量。输入包括多个测试用例,每个用例给出一系列点坐标;输出则是每个用例中可以构成的不同正多边形数量。
358

被折叠的 条评论
为什么被折叠?



