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数降序刷 ---------------------------- ...
随机推荐
- Binary Tree Traversal
1.Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' values. For ex ...
- 关于xmlhttprequest的readystate属性的五个状态
http://www.cnblogs.com/jerry01/archive/2009/09/03/1559624.html 昨天做了一个利用 ajax实现页面无刷新的从服务器端获得时间的例子,当时对 ...
- 全国信息学奥林匹克联赛(NOIP2014)复赛 模拟题Day2 长乐一中
题目名称 改造二叉树 数字对 交换 英文名称 binary pair swap 输入文件名 binary.in pair.in swap.in 输出文件名 binary.out pair.out sw ...
- HTML初讲
整理老师所讲: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- hihoCoder#1055 : 刷油漆 (树形DP+01背包)
题目大意:给一棵带点权的树,现在要从根节点开始选出m个连通的节点,使总权值最大. 题目分析:定义状态dp(u,m)表示在以u为根的子树从根节点开始选出m个点连通的最大总权值,则dp(u,m)=max( ...
- c语言开发手机通讯录
// // main.c // 手机通讯录 // // Created by Kevin-Dfg on 16/4/19. // Copyright © 2016年 Kevin-Dfg. All ...
- Codeforces Round #339 Div.2 C - Peter and Snow Blower
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. A ...
- JSBinding + SharpKit / JavaScript 加载流程
首先,现在的方案是游戏启动就加载全部的 JavaScript 代码. 先看下 StreamingAssets/JavaScript/ 文件夹下的目录结构:
- Avoiding PostgreSQL database corruption
TL;DR: Don't ever set fsync=off, don't kill -9 the postmaster then deletepostmaster.pid, don't run P ...
- SQL Server系统数据库
Master Master数据库保存有放在SQLSERVER实体上的所有数据库,它还是将引擎固定起来的粘合剂.由于如果不使用主数据库,SQLSERVER就不能启动,所以你必须要小心地管理好这个数据库. ...