题意:给你平面上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. http over git server

    编译安装git 参考 <CentOS7编译安装git> 安装httpd yum install httpd -y 安装gitweb yum install gitweb -y 创建项目根目 ...

  2. what have we learnt in day five

    what is file? virtual unit offered by operation system steps to open file 1.find the file_path(file_ ...

  3. unlocked - 非锁定的标准输入输出函数

    SYNOPSIS 总览 #include <stdio.h> int getc_unlocked(FILE *stream); int getchar_unlocked(void); in ...

  4. Codeforces346D. Robot Control

    D. Robot Control time limit per test 6 seconds memory limit per test 256 megabytes input standard in ...

  5. Dubbo支持的注册中心有哪些?

    1.Dubbo协议(官方推荐协议) 优点: 采用NIO复用单一长连接,并使用线程池并发处理请求,减少握手和加大并发效率,性能较好(推荐使用) 缺点: 大文件上传时,可能出现问题(不使用Dubbo文件上 ...

  6. Aria2 Centos8 安装配置

    使用chkconfig 或者 chkconfig –list就可以看出当前系统已经设置的各个服务在各个运行级别下的开闭状态.如果我们想设置某个服务自启动或者关闭的话,那么只需要按照下面的格式使用即可 ...

  7. bzoj1037题解

    [解题思路] DP.f[i][j][x][y]表示已选了i个♂和j个♀,其中♂比♀多x,♀比♂多y(x,y≥0). 递推式转移方程: (f[i+1][j][x+1][max(y-1,0)]+=f[i] ...

  8. BZOJ 4817: [Sdoi2017]树点涂色(lct+线段树)

    传送门 解题思路 跟重组病毒这道题很像.只是有了一个询问\(2\)的操作,然后询问\(2\)的答案其实就是\(val[x]+val[y]-2*val[lca(x,y)]+1\)(画图理解).剩下的操作 ...

  9. NX二次开发-UFUN拾取草图尺寸对话框UF_UI_select_sketch_dimensions

    #include <uf.h> #include <uf_ui.h> #include <uf_sket.h> UF_initialize(); //拾取草图尺寸对 ...

  10. nginx、php-fpm安装mongodb及驱动扩展

    1.安装mongodb linux下安装mongodb很简单,执行如下命令完成安装 wget http://downloads.mongodb.org/linux/mongodb-linux-i686 ...