hdu 6055 Regular polygon

来源:互联网 发布:centos 安装lamp环境 编辑:程序博客网 时间:2024/05/31 13:14

枚举两个点,然后计算出正方形两外两个点,然后查找有没有这两个点。
这里写图片描述
在此之前真不知道怎么根据两点算另外两点,几何都白学了这里写图片描述
因为每个边都枚举一次,所以要除以4

#include <bits/stdc++.h>#define ll long longusing namespace std;struct Point{    int x,y;} p[555];set<pair<int,int>> sets;int solve(Point a,Point b){    int x=a.x-b.x;    int y=a.y-b.y;    int ans=0;    if(sets.count(make_pair(a.x+y,a.y-x)) > 0&& sets.count(make_pair(b.x+y,b.y-x)) > 0)        ++ans;    if(sets.count(make_pair(a.x-y,a.y+x)) > 0&& sets.count(make_pair(b.x-y,b.y+x)) > 0)        ++ans;    return ans;}int main(){    int n,a,b;    while(~scanf("%d",&n))    {        sets.clear();        for(int i=0; i<n; i++)        {            scanf("%d%d",&a,&b);            p[i].x=a;            p[i].y=b;            sets.insert(make_pair(a,b));        }        int ans=0;        for(int i=0; i<n; i++)            for(int j=i+1; j<n; j++)                    ans+=solve(p[i],p[j]);        printf("%d\n",ans/4);    }}
原创粉丝点击