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;}
- BZOJ 2592 [Usaco2012 Feb] Symmetry
- bzoj 2592 [Usaco2012 Feb]Symmetry
- 【bzoj2590】[Usaco2012 Feb]Cow Coupons
- 【BZOJ】3016: [Usaco2012 Nov]Clumsy Cows
- BZOJ 3012/Luogu 3065 [Usaco2012 Dec]First!
- BZOJ 3016: [Usaco2012 Nov]Clumsy Cows
- bzoj 3018: [Usaco2012 Nov]Distant Pastures
- bzoj 3016: [Usaco2012 Nov]Clumsy Cows 栈
- Symmetry
- Symmetry
- BZOJ 3943 [Usaco2015 Feb]SuperBull
- BZOJ 3940 [Usaco2015 Feb]Censoring
- BZOJ 3942 [Usaco2015 Feb] Censoring
- BZOJ 3940 [Usaco2015 Feb] Censoring
- bzoj 3943: [Usaco2015 Feb]SuperBull
- [Meet In Middle] BZOJ 2679 [Usaco2012 Open]Balanced Cow Subsets
- bzoj 2679: [Usaco2012 Open]Balanced Cow Subsets 折半搜索
- BZOJ 2679: [Usaco2012 Open]Balanced Cow Subsets meet_in_the_middle / 折半搜索
- Android学习笔记——Intent
- 百度站内搜索代码
- java list 交集 并集 差集 去重复并集
- ISP-坏点校正(DPC)
- Java设计模式之创建型模式--工厂方法及抽象工厂模式
- bzoj 2592 [Usaco2012 Feb]Symmetry
- C++ STL容器
- angularJs路由操作实例(一)
- 关于logicbrick(xylon)的ip安装
- SSM(spring+spring mvc+mybatis)框架搭建
- 【机器学习实战】Machine Learning in Action 代码 视频 项目案例
- 6、vim常用操作
- Spring MVC 跨域问题
- C++ 常识