题意:给你平面上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. 普通浏览器实现点击打开微信app

    给予点击事件,然后调用以下方法即可(我这用的是jq的点击): $(function() { Cz.Alert().success({text: '请返回公众号查看充值结果'}); $(".a ...

  2. [JZOJ6353] 【NOIP2019模拟】给

    题目 题目大意 对于所有的整数\(k \in [1,n]\),求叶子结点有\(k\)个的二叉树个数,满足每个非叶子结点都有两个儿子,并且对于每个叶子结点,从根节点到它经过的向左的边数少于等于\(m\) ...

  3. ETL工具-Kattle:查询 HTTP/WebService

      发送HTTP POST请求,获取返回内容.  发送HTTP GET请求,获取返回内容,可以从前面获取URL.参数名.参数值 通过Restful获取数据 通过webService获取数据 HTTP ...

  4. PHP rand() 函数

    定义和用法 rand() 函数生成随机整数. 提示:如果您想要一个介于 10 和 100 之间(包括 10 和 100)的随机整数,请使用 rand (10,100). 提示:mt_rand() 函数 ...

  5. poi之Excel上传

    poi之Excel上传 @RequestMapping(value = "/import", method = RequestMethod.POST) public String ...

  6. 【Codeforces Round #429 (Div. 2) B】 Godsend

    [Link]:http://codeforces.com/contest/841/problem/B [Description] 两个人轮流对一个数组玩游戏,第一个人可以把连续的一段为奇数的拿走,第二 ...

  7. Python 爬取12306火车票

    获取火车站 stations.py #import certifi #import urllib3 import re import requests from pprint import pprin ...

  8. 嘶吼CTF2019总结(Web部分题目复现以及部分杂项)

    easy calc 这次的比赛自己一题都没有做出来,赛后看题解的时候很难受,其实有很多东西自己其实是可以做出来的,但是思路被限制了,可能这就是菜吧. 首先web题目就是一个easy calc,emmm ...

  9. NX二次开发-对话框解锁UF_UI_unlock_ug_access

    VC/MFC调用UG Dialog要进入加锁状态 加锁 UF_UI_lock_ug_access ( UF_UI_FROM_CUSTOM ); 此处为UF_UI_select的函数 解锁 UF_UI_ ...

  10. [luogu 4389] 付公主的背包

    题意:求一个较大的多重背包对于每个i的方案数,答案对998244353取模. 思路: 生成函数: 对于一个\(V\) 设: \(f(x) = \sum_{i=0}^{oo} x ^ {V * i} = ...