【2017多校第二场】HDU 6055 Regular polygon【几何,枚举】

来源:互联网 发布:阿里云大厦有什么公司 编辑:程序博客网 时间:2024/06/01 23:26

Regular polygon

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


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
40 00 11 01 160 00 11 01 12 02 1
 

Sample Output
12
 

Source
2017 Multi-University Training Contest - Team 2


原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6055

题意:题意,二维平面上给N个整数点,问能构成多少个不同的正多边形。 题解:容易得知只有正四边形可以使得所有的顶点为整数点。(具体证明可参考杨景钦在2017的国家队论文) 所以正解即求出所有的正四边形个数。 枚举2个点,然后暴力判断另外2个点的位置是否存在。 复杂度 N*N*logN。

解:

坐标都是整数输入,那么整数坐标能组成的正多边形只有正方形。

但正方形的位置是随意的。

让后我们会发现正方形可以分解为四个直角三角形。

如图:

然后,我们就能得到四个点的坐标关系:

我们根据两个点,就可以判断是否存在两个正方形(左上方还有一个,原作者未画出来)

因为所给出的坐标是整数,满足整这个条件的正多边形只有正方形,所以我们把每两个点枚举一遍,看看是否存在形成正方形另外两个点,因为把每一个边都枚举了一遍,所以最后的答案要除以4


枚举的时候,知道了两个点,每两个点我们要在它的左右两边找正方形,所以我们要判断两次


参考博客:

http://blog.csdn.net/riba2534/article/details/76216159

http://blog.csdn.net/no2015214099/article/details/76223670

http://blog.csdn.net/qq_28954601/article/details/76216129

http://www.cnblogs.com/hhxj/p/7246752.html


AC代码:

/**  * 行有余力,则来刷题!  * 博客链接:http://blog.csdn.net/hurmishine  * 个人博客网站:http://wuyunfeng.cn/*//**http://blog.csdn.net/riba2534/article/details/76216159http://blog.csdn.net/no2015214099/article/details/76223670http://blog.csdn.net/qq_28954601/article/details/76216129http://www.cnblogs.com/hhxj/p/7246752.html*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=500+5;struct Node{    int x,y;}node[maxn];bool vis[maxn][maxn];int solve(Node a,Node b){    int x=a.x-b.x;    int y=a.y-b.y;    int ans=0;    if(a.x+y>=0&&a.y-x>=0&&b.x+y>=0&&b.y-x>=0&&vis[a.x+y][a.y-x]&&vis[b.x+y][b.y-x])        ans++;    if(a.x-y>=0&&a.y+x>=0&&b.x-y>=0&&b.y+x>=0&&vis[a.x-y][a.y+x]&&vis[b.x-y][b.y+x])        ans++;    return ans;}int main(){    //freopen("C:\\Users\\hncu_acm\\Desktop\\data.txt","r",stdin);    int n;    while(cin>>n)    {        memset(vis,false,sizeof(vis));        int x,y;        for(int i=0;i<n;i++)        {            scanf("%d%d",&x,&y);            x+=100;            y+=100;            node[i].x=x;            node[i].y=y;            vis[x][y]=true;        }        int ans=0;        for(int i=0;i<n;i++)        {            for(int j=i+1;j<n;j++)            {                if(i!=j)                {                    ans+=solve(node[i],node[j]);                }            }        }        cout<<ans/4<<endl;    }}/**4-1 00 -10 11 0*/



阅读全文
0 0
原创粉丝点击