题意:给你平面上n个点,问有多少条过原点的直线,使得这些点在该直线上的投影(做垂直,对应点)形成对称图形?n<=2000。

标程:

 #include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int inf=0x3f3f3f3f;
const double eps=1e-;
const int N=;
struct node{double x,y,k;int px,py;}a[N*N];
double mid_x,mid_y;
int n,x[N],y[N],ans,k,t,p[N],die[N],X[N],Y[N],cnt,lst,pos;
bool cmp (const node &A,const node &B) {return A.k<B.k;}
bool operator == (const node &A,const node &B) {return A.x*B.y==A.y*B.x;}
bool check(int x,double b1,double b2)//double不要开成int!
{
double dx=mid_y-Y[x],dy=-mid_x+X[x];
return fabs(dy*b1-b2*dx)<eps;
}
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%d%d",&x[i],&y[i]),mid_x+=x[i],mid_y+=y[i];
mid_x/=n;mid_y/=n;
for (int i=;i<n;i++)
if (!die[i])
for (int j=i+;j<=n;j++)
if (!die[j]&&fabs(x[i]+x[j]-*mid_x)<eps&&fabs(y[i]+y[j]-*mid_y)<eps) {die[i]=die[j]=;break;}
for (int i=;i<=n;i++) if (!die[i]) X[++t]=x[i],Y[t]=y[i];
if (t<) return puts("-1"),;
for (int i=;i<t;i++)
for (int j=i+;j<=t;j++)
{
double dx=mid_y-(Y[i]+Y[j])/2.0,dy=-mid_x+(X[i]+X[j])/2.0;//垂直,斜率负倒数
if (dx<) dx=-dx,dy=-dy;
if (dx==) dy=fabs(dy);
if (dy==) dx=fabs(dx);//!!!
a[++cnt].x=dx,a[cnt].y=dy;a[cnt].px=i;a[cnt].py=j;a[cnt].k=atan2(dy,dx);
}
sort(a+,a+cnt+,cmp);lst=;
for (int i=;i<=cnt;i++)//check and count
if (i==cnt||!(a[i]==a[i+]))
{
if (i-lst+>=t/)
{
for (int j=;j<=t;j++) p[j]=;
for (;lst<=i;lst++)
if (p[a[lst].px]&&p[a[lst].py]) p[a[lst].px]=p[a[lst].py]=;//注意重合的两点不能同时和另一点匹配!一配一
k=;
for (int j=;j<=t;j++) if (p[j]) k++,pos=j;
if (k>(t&)) continue;
if (!k||check(pos,a[i].x,a[i].y)) ans++;
}
lst=i+;
}
printf("%d\n",ans);
return ;
}

易错点:1.double不要开成int

2.比较斜率相等的时候,不要比较k关键字,直接用x和y关键字的乘积比较即可。由于最多带小数0.5,所以不会有误差, 直接==即可。

题解:计算几何

一开始的想法是坐标系旋转解旋转角。

正解如下,

找到该图形的重心,易证不管怎么旋转,对称轴一定经过重心。

如果一对点关于重心对称,那么不管怎么旋转这两个点到对称轴的距离都相等,匹配上,删去。

由此发现剩下来的点,n^2枚举两个点作为对称点,有且仅有一条直线满足这两个点的投影在其上关于经过重心的直线对称。

check直线是否符合条件:

如果一条相同斜率的直线出现次数>=n/2,那么说明有足够多的对称点对在其上。看是否能否匹配完所有点,如果n是偶数一定能匹配完,n是奇数会多出一个看是否恰好在对称轴上。

时间复杂度O(n^2)。

CF886F Symmetric Projections的更多相关文章

  1. Codeforces886(Technocup2018) F Symmetric Projections

    Codeforces886(Technocup2018) F Symmetric Projections You are given a set of n points on the plane. A ...

  2. Codeforces Round #445

    ACM ICPC 每个队伍必须是3个人 #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu ...

  3. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

  4. [LeetCode] Symmetric Tree 判断对称树

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  5. Event Store 2.0发布,带来了安全支持和测试版Projections库

    Event Store 2.0版本于上周发布,它带来了安全支持允许锁定Event Store和在事件流上设置访问控制列表.其主要新特性包括: HTTP和TCP之上的身份认证,包括账户管理 测试版Pro ...

  6. Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  7. SYMMETRIC MULTIPROCESSORS

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION As demands for perfor ...

  8. 【LeetCode OJ】Symmetric Tree

    Problem Link: https://oj.leetcode.com/problems/symmetric-tree/ To solve the problem, we can traverse ...

  9. (Tree) 101. Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

随机推荐

  1. Android高级架构进阶之数据传输与序列化

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从以下几个内容来阐述数据传输与序列化: [Serializable原理] ...

  2. 6.2_springboot2.x分布式整合Dubbo

    1.分布式应用 ​ 在分布式系统中,国内常用zookeeper+dubbo组合,而Spring Boot推荐使用全栈的Spring,Spring Boot+Spring Cloud. 分布式系统: 特 ...

  3. python xlwt设置单元格的自定义背景颜色

    我使用python 2.7和xlwt模块进行excel导出 我想设置我知道可以使用的单元格的背景颜色 style1 = xlwt.easyxf('pattern: pattern solid, for ...

  4. 「CSP-S 2019」树的重心

    题目 考场上送\(75pts\)真实良心,正解不难:考虑直接对于每一个点算割掉多少条边能使得这个点成为重心,不难发现对于一个不是重心的点,我们要割掉的那条边一定在那个大于\(\lfloor \frac ...

  5. 数据可视化echart

    刚接到这个一脸懵逼,到现在还算有点眉目,先上个图庆祝一下,哈哈,开心.... 最近没时间,等待更新..........

  6. Dubbo多注册中心和Zookeeper服务的迁移

    一.Dubbo多注册中心 1. 应用场景 例如阿里有些服务来不及在青岛部署,只在杭州部署,而青岛的其它应用需要引用此服务,就可以将服务同时注册到两个注册中心. consumer.xml <?xm ...

  7. OAuth2.0实例说明

    OAuth2.0 详细实列+Word文档清晰说明 实例下载地址:https://files.cnblogs.com/files/liyanbofly/OAuth2.0%E5%AE%9E%E4%BE%8 ...

  8. xpdf -Portable Document Format(PDF)文件阅读器

    总览 xpdf [选项] [PDF文件 [page]] 描述 Xpdf是一个 Portable Document Format(PDF) 文件阅读软件.(PDF文件也经常被称为Acrobat 文件,这 ...

  9. Spring boot热部署实战

    1.介绍 在开发工程中,修改一点儿代码,想看效果就需要重新启动服务,这样会花费大量时间在重启服务上,通过devtools热部署可以大大减少重启服务的时间. 之所以能减少时间,是因为Spring Boo ...

  10. PHP 实现斐波那契数列

    使用循环实现 <?php $arr[1] = 1; for($i = 2;$i < 100;$i++) { $arr[$i] = $arr[$i-1] + $arr[$i-2]; } ec ...