题意:给你平面上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. Servilet初步

    以http://locahost:8080/......开头,或者以/开头,都是绝对路径以路径开头:相对路径 路径/路径 Servlet执行流程:(只用自己编写执行的代码,执行的细节全是tomcat封 ...

  2. [Code+#3]博弈论与概率统计

    题目 记得曾经和稳稳比谁后抄这个题的题解,看来是我输了 不难发现\(p\)是给着玩的,只需要求一个总情况数除以\(\binom{n+m}{n}\)就好了 记\(i\)为无效的失败次数,即\(\rm A ...

  3. [USACO06JAN]牛的舞会The Cow Prom

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  4. nuxt 项目启动报错(HTMLElement is not define nuxt.js)

    这两天研究服务端渲染,折腾nuxt,搞得真是心累. 各种报错,nuxt 真是坑多啊,且来说说遇到哪些问题, 1. 搭建nuxt , npx create-nuxt-app <项目名> cd ...

  5. Java泛型中extends和super的区别?

    <? extends T>和<? super T>是Java泛型中的"通配符(Wildcards)"和"边界(Bounds)"的概念. ...

  6. 代码托管平台--GitHub 使用小结

    一.GitHub介绍 GitHub是一个面向开源及私有软件项目的托管平台,因为只支持git作为唯一的版本库格式进行托管.在GitHub,用户可以十分轻易地找到海量的开源代码. 很多IT行业的人到求职的 ...

  7. 2019南京网络赛 D Robots 期望dp

    题目传送门 题意:给出一幅有向无环图,保证只有1入度为0,n出度为0,求问一个机器人从1出发,每天等概率的走到相邻点或者留在原地,问到达n点的代价.每天的代价都不一样,就是天数(第x天走一步的代价就是 ...

  8. 毫秒数转date

    毫秒数转date var date=new date(毫秒数);

  9. python_django_urls模块与views模块请求访问过程

    diango接收到web请求后的在urls模块与views模块进行的过程操作: 匹配过程: urls拿到网址,在项目级urls中匹配,若在urlpatterns中存在,则跳转到应用级urls中匹配,若 ...

  10. vue 单元素过渡

    demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...