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.

圆上的整点很少,所以可以找出点集的重心并把点按到重心的距离排序,到重心相同距离的点在同一圆上,计算这些点的对称轴(最多四条),最后取交集即可,时间复杂度是O(n2logn)但因为整点且范围小所以不会达到最坏情况

#include<bits/stdc++.h>
typedef long double ld;
const ld pi=std::acos(-),_0=1e-7l;
int n,ans=,xs=,ys=,lp=,ap=,ad=;
struct pos{int x,y;long long d;ld a;}ps[];
ld ls[],as[];
bool operator<(pos a,pos b){
return a.d!=b.d?a.d<b.d:a.a<b.a;
}
ld dis(ld x,ld y){
return std::sqrt(x*x+y*y);
}
int fix(int a,int l,int r){
if(a<l)return a+r-l;
if(a>=r)return a-r+l;
return a;
}
bool feq(ld a,ld b){
return fabs(a-b)<_0;
}
bool chk(ld x){
while(x>pi*-_0)x-=pi*;
while(x<_0-pi*)x+=pi*;
return std::fabs(x)<_0;
}
int main(){
scanf("%d",&n);
for(int i=;i<n;i++)scanf("%d%d",&ps[i].x,&ps[i].y);
for(int i=;i<n;i++){
xs+=ps[i].x;
ys+=ps[i].y;
}
for(int i=;i<n;i++){
(ps[i].x*=n)-=xs;
(ps[i].y*=n)-=ys;
ps[i].d=1ll*ps[i].x*ps[i].x+1ll*ps[i].y*ps[i].y;
ps[i].a=atan2(ps[i].y,ps[i].x);
}
std::sort(ps,ps+n);
int p0=,p1;
while(ps[p0].x==&&ps[p0].y==)++p0;
for(p1=p0;p0<n;p0=p1){
while(p1<n&&ps[p1].d==ps[p0].d)++p1;
lp=;
for(int p2=p0;p2<p1;p2++){
bool ab=;
ld m=ps[p2].a*;
for(int l=fix(p2-,p0,p1),r=fix(p2+,p0,p1);;l=fix(l-,p0,p1),r=fix(r+,p0,p1)){
if(!chk(ps[l].a+ps[r].a-m)){
ab=;
break;
}
if(l==r)break;
}
if(ab==)ls[lp++]=ps[p2].a;
if(p1-p0&)continue;
ab=;
m=(ps[p2].a+ps[fix(p2+,p0,p1)].a);
for(int l=fix(p2,p0,p1),r=fix(p2+,p0,p1),t=p1-p0>>;t;--t,l=fix(l-,p0,p1),r=fix(r+,p0,p1)){
if(!chk(ps[l].a+ps[r].a-m)){
ab=;
break;
}
if(l==r)break;
}
if(ab)ls[lp++]=m/.;
}
for(int i=;i<lp;i++){
ld x=ls[i];
while(x<-_0)x+=pi;
while(x>pi-_0)x-=pi;
ls[i]=x;
}
std::sort(ls,ls+lp);
lp=std::unique(ls,ls+lp,feq)-ls;
if(ad){
int lp1=,ap1=;
for(int i=;i<ap;i++){
while(lp1<lp&&ls[lp1]<as[i]-_0)++lp1;
if(lp1==lp)break;
if(feq(as[i],ls[lp1]))as[ap1++]=as[i];
}
ap=ap1;
}else{
ad=;
for(int i=;i<lp;i++)as[ap++]=ls[i];
}
}
printf("%d",ap);
return ;
}

bzoj2592: [Usaco2012 Feb]Symmetry的更多相关文章

  1. 2590: [Usaco2012 Feb]Cow Coupons

    2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 306  Solved: 154[Su ...

  2. [Usaco2012 Feb] Cow Coupons

    [Usaco2012 Feb] Cow Coupons 一个比较正确的贪心写法(跑得贼慢...) 首先我们二分答案,设当前答案为mid 将序列按照用券之后能省掉的多少排序,那么我们对于两种情况 \(m ...

  3. BZOJ2590 [Usaco2012 Feb]Cow Coupons

    好吧...想了半天想错了...虽然知道是贪心... 我们每次找没有被买的两种价格最小的牛,比较a = 当前差价最大的 + 当前优惠券价格最小的牛与b = 当前非优惠券价格最小的牛 所以...我们要 先 ...

  4. 【贪心】【堆】bzoj2590 [Usaco2012 Feb]Cow Coupons

    每个物品有属性a,b 考虑在仅仅用光优惠券时的最优方案. 显然是按照b排序,取前K个. 但是我们还要尽可能去取剩余的. 假设朴素地取剩余的话,应该把剩余的对a排序,然后尽量去取. 但是有可能对其用优惠 ...

  5. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  6. USACO 2012 Feb Cow Coupons

    2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Su ...

  7. bzoj usaco 金组水题题解(2.5)

    bzoj 2197: [Usaco2011 Mar]Tree Decoration 树形dp..f[i]表示处理完以i为根的子树的最小时间. 因为一个点上可以挂无数个,所以在点i上挂东西的单位花费就是 ...

  8. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  9. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

随机推荐

  1. Container ViewController初探1

    今天调试程序遇到个问题,iOS7下在弹出Modal的子界面时,弹出层次不对,键盘和界面被分割在了Window的两侧,导致显示异常Presenting view controllers on detac ...

  2. leetcode 144. Binary Tree Preorder Traversal ----- java

    Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...

  3. 黑马程序员——JAVA基础之多态与Object

    ------- android培训.java培训.期待与您交流! ----------  多态 : 多态定义:  某一类事物的多种存在形态. 多态的体现: 父类的引用指向了自己的子类对象.       ...

  4. .c和.h文件的区别(转载)

    一个简单的问题:.c和.h文件的区别学了几个月的C语言,反而觉得越来越不懂了.同样是子程序,可以定义在.c文件中,也可以定义在.h文件中,那这两个文件到底在用法上有什么区别呢? 2楼:子程序不要定义在 ...

  5. (转) Reinforcement Learning for Profit

    Reinforcement Learning for Profit July 17, 2016 Is RL being used in revenue generating systems today ...

  6. linux 大并发下 内核优化

     To support over 500k users, you *need* - A 64 bits hardware/kernel (AMD64, Opterons) - At least 8GB ...

  7. java 将长度很长的字符串(巨大字符串超过4000字节)插入oracle的clob字段时会报错的解决方案

    直接很长的字符串插入到clob字段中会报字符过长的异常,相信大家都会碰到这种情况 String sql = "insert into table(request_id,table_name, ...

  8. viewPage

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  9. Linux服务器上监控网络带宽的18个常用命令(转)

    本文介绍了一些可以用来监控网络使用情况的Linux命令行工具.这些工具可以监控通过网络接口传输的数据,并测量目前哪些数据所传输的速度.入站流量和出站流量分开来显示. 一些命令可以显示单个进程所使用的带 ...

  10. shell知识点

    各个项目以实践为主.原理及更多细节介绍,请查看官方文档: 例如:bash,grub,postfix,pam,fastcgi,httpd,rsync等诸多项目. 各种总结表格 http://www.cn ...