bzoj2592: [Usaco2012 Feb]Symmetry
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的更多相关文章
- 2590: [Usaco2012 Feb]Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 306 Solved: 154[Su ...
- [Usaco2012 Feb] Cow Coupons
[Usaco2012 Feb] Cow Coupons 一个比较正确的贪心写法(跑得贼慢...) 首先我们二分答案,设当前答案为mid 将序列按照用券之后能省掉的多少排序,那么我们对于两种情况 \(m ...
- BZOJ2590 [Usaco2012 Feb]Cow Coupons
好吧...想了半天想错了...虽然知道是贪心... 我们每次找没有被买的两种价格最小的牛,比较a = 当前差价最大的 + 当前优惠券价格最小的牛与b = 当前非优惠券价格最小的牛 所以...我们要 先 ...
- 【贪心】【堆】bzoj2590 [Usaco2012 Feb]Cow Coupons
每个物品有属性a,b 考虑在仅仅用光优惠券时的最优方案. 显然是按照b排序,取前K个. 但是我们还要尽可能去取剩余的. 假设朴素地取剩余的话,应该把剩余的对a排序,然后尽量去取. 但是有可能对其用优惠 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- USACO 2012 Feb Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Su ...
- bzoj usaco 金组水题题解(2.5)
bzoj 2197: [Usaco2011 Mar]Tree Decoration 树形dp..f[i]表示处理完以i为根的子树的最小时间. 因为一个点上可以挂无数个,所以在点i上挂东西的单位花费就是 ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
随机推荐
- Handler 引起的内存泄露
先看一组简单的代码 1 2 3 4 5 6 7 8 9 public class SampleActivity extends Activity { private final Handler mHa ...
- 总结 output 用法
第一种用法 返回受 INSERT.UPDATE 或 DELETE 语句影响的每行的信息,或者返回基于上述每行的表达式.这些结果可以返回到处理应用程序, 以供在确认消息.存档以及其他类似的应用程序要求中 ...
- Vimium 快捷键记录
, <c-e> : Scroll down k, <c-y> : Scroll up h : Scroll left l : Scroll right gg : Scroll ...
- URAL 1218 Episode N-th: The Jedi Tournament(强连通分量)(缩点)
Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Kni ...
- phpwind8.7升级9.0.1过程(一)本地和服务器数据同步的部署
在使用phpwind的过程中需要将整个网站论坛的模板从phpwind8.7升级到phpwind9.0.1 需要首先在本地搭建和服务器端一样的环境然后在本地尝试性升级之后,然后在服务器端进行升级. 以下 ...
- 越狱Season 1-Episode 6: Riots, Drills and the Devil: Part 1
Season 1, Episode 6: Riots, Drills and the Devil: Part 1 - Diamond: Just a few more rides. 就再多玩几次吧 O ...
- 【SDOI2008】【P1377】仪仗队
欧拉函数的应用 原题: 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是 ...
- android基础知识13:AndroidManifest.xml文件解析
注:本文转载于:http://blog.csdn.net/xianming01/article/details/7526987 AndroidManifest.xml文件解析. 1.重要性 Andro ...
- Unity Meshes
1. Unity 没有自带建模工具 2. 导入 Mesh 时,Unity 会自动寻找所引用的纹理,查找文件夹名为 Textures 的.先在本目录下找 -> 上溯在parent查找 ==> ...
- Don’t Assume – Per Session Buffers
MySQL has a number of global buffers, i.e. your SGA. There are also a number of per session/thread b ...