bzoj 2592 [Usaco2012 Feb]Symmetry

来源:互联网 发布:网络购物市场交易规模 编辑:程序博客网 时间:2024/06/07 15:05

Time Limit: 5 Sec Memory Limit: 128 MB
Submit: 110 Solved: 55
[Submit][Status][Discuss]
Description

After taking a modern art class, Farmer John has become interested in finding geometric patterns in everything around his farm. He carefully plots the locations of his N cows (2 <= N <= 1000), each one occupying a distinct point in the 2D plane, and he wonders how many different lines of symmetry exist for this set of points. A line of symmetry, of course, is a line across which the points on both sides are mirror images of each-other. Please help FJ answer this most pressing geometric question.

上过现代艺术课后,FJ开始感兴趣于在他农场中的几何图样。他计划将奶牛放置在二维平面上的N个互不相同的点(1<=N<=1000),他希望找出这个点集有多少条对称轴。他急切地需要你帮忙解决这个几何问题。

Input

  • Line 1: The single integer N.

  • Lines 2..1+N: Line i+1 contains two space-separated integers representing the x and y coordinates of the ith cow (-10,000 <= x,y <= 10,000).

Output

  • Line 1: The number of different lines of symmetry of the point set.

Sample Input

4

0 0

0 1

1 0

1 1

Sample Output

4
HINT

Source

Gold

[Submit][Status][Discuss]

HOME Back


【分析】
学习无力,迟早退役。


【代码】

//bzoj 2592 [Usaco2012 Feb]Symmetry#include<bits/stdc++.h>#define eps 1e-8#define ll long long#define M(a) memset(a,0,sizeof a)#define fo(i,j,k) for(int i=j;i<=k;i++)using namespace std;const int mxn=1005;int n,ans;inline int equ(double x){    if(fabs(x)<eps) return 0;return 1;}struct point{    double x,y;    point() {x=y=0;}    point(double a,double b) {x=a,y=b;}    point operator + (const point &b) const    {return point(x+b.x,y+b.y);}    point operator - (const point &b) const    {return point(x-b.x,y-b.y);}    point operator * (const double &b) const    {return point(x*b,y*b);}    inline double cross(const point &a,const point &b) const    {return (a.x-x)*(b.y-y)-(b.x-x)*(a.y-y);}    inline bool operator < (const point &b) const    {return equ(x-b.x)?x<b.x:y<b.y;}    inline bool operator == (const point &b) const    {return !equ(x-b.x) && !equ(y-b.y);}        }p[mxn],t1,t2;set <point> s;inline point linecross(point a,point b,point c,point d){    double u=a.cross(b,c),v=b.cross(a,d);    return point((c.x*v+d.x*u)/(u+v),(c.y*v+d.y*u)/(u+v));}inline point anti(point p,point a,point b){    if(a==b) return point(a.x+a.x-p.x,a.y+a.y-p.y);    point tmp(p.x+a.y-b.y,p.y+b.x-a.x);    return linecross(p,tmp,a,b)*2-p;}inline int judge(point a,point b){    fo(i,1,n)      if(!s.count(anti(p[i],a,b))) return 0;    return 1;}inline bool make(point a,point b,point &c,point &d){    if(a==b) return 0;    c=(a+b)*0.5;    d=point(c.x+a.y-b.y,c.y+b.x-a.x);    return 1;}int main(){    scanf("%d",&n);    fo(i,1,n)    {        scanf("%lf%lf",&p[i].x,&p[i].y);        s.insert(p[i]);    }    ans+=judge(p[1],p[2]);    make(p[1],p[2],t1,t2);    ans+=judge(t1,t2);    fo(i,3,n)    {        make(p[1],p[i],t1,t2);        ans+=judge(t1,t2);        make(p[2],p[i],t1,t2);        ans+=(judge(t1,t2)&&!equ(p[1].cross(t1,t2)));    }    printf("%d\n",ans);    return 0;}