思路:

放yousiki大爷题解

http://yousiki.net/index.php/archives/82/

我写的是随机化

既然gzz证了最终答案的上界是O(N)的

那么我们可以n^2枚举所有的点对

先pretest判一发 (随机10个点  找找有没有对称点)  如果过了pretest再O(n)的判

整体复杂度是$O(n^2logn)$的

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
const int mod=,N=;
int n,xx,yy,ans=;
struct Point{double x,y;Point(){}Point(double X,double Y){x=X,y=Y;}}point[N];
Point operator-(Point a,Point b){return Point(a.x-b.x,a.y-b.y);}
double operator*(Point a,Point b){return a.x*b.y-a.y*b.x;}
bool operator<(Point a,Point b){if(a.x==b.x)return a.y<b.y;return a.x<b.x;}
struct Line{Point a,b;Line(){}Line(Point X,Point Y){a=X,b=Y;}}stk[N*];
Line get_line(int i,int j){
Point x=Point((point[i].x+point[j].x)/,(point[i].y+point[j].y)/);
Point y=Point(x.x+point[j].y-point[i].y,x.y-point[j].x+point[i].x);
return Line(x,y);
}
double dis(Point a,Point b){a=a-b;return sqrt(a.x*a.x+a.y*a.y);}
Point get_point(Point p,Line ln){
double d=(ln.b-ln.a)*(p-ln.a)/dis(ln.a,ln.b)*,x=ln.b.y-ln.a.y,y=ln.a.x-ln.b.x,s=sqrt(x*x+y*y);
return Point(p.x+x*d/s,p.y+y*d/s);
}
bool pretest(Line ln){
for(int i=;i<=;i++){
Point p=get_point(point[rand()%n+],ln);
double x=round(p.x),y=round(p.y);
if(abs(x-p.x)>1e-||abs(y-p.y)>1e-)return ;
Point f=Point(x,y);
int t=lower_bound(point+,point++n,f)-point;
if(t>n||abs(point[t].x-f.x)>1e-||abs(point[t].y-f.y)>1e-)return ;
}return ;
}
bool test(Line ln){
for(int i=;i<=n;i++){
Point p=get_point(point[i],ln);
double x=round(p.x),y=round(p.y);
if(abs(x-p.x)>1e-||abs(y-p.y)>1e-)return ;
Point f=Point(x,y);
int t=lower_bound(point+,point++n,f)-point;
if(t>n||abs(point[t].x-f.x)>1e-||abs(point[t].y-f.y)>1e-)return ;
}return ;
}
bool check(Line tmp){for(int i=;i<=ans;i++)if(abs((stk[i].a-stk[i].b)*(tmp.a-tmp.b))<1e-)return ;return ;}
int main(){
srand();scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&xx,&yy),point[i]=Point(1.0*xx,1.0*yy);
sort(point+,point++n);
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++){
Line tmp=get_line(i,j);
if(check(tmp)&&pretest(tmp)&&test(tmp))stk[++ans]=tmp;
tmp=Line(point[i],point[j]);
if(check(tmp)&&pretest(tmp)&&test(tmp))stk[++ans]=tmp;
}
printf("%d\n",ans);
}

BZOJ 2592 随机化(伪)的更多相关文章

  1. @bzoj - 4524@ [Cqoi2016]伪光滑数

    目录 @description@ @solution@ @version - 1@ @version - 2@ @accepted code@ @version - 1@ @version - 2@ ...

  2. Bzoj 4524 [Cqoi2016]伪光滑数(堆)

    题面 题解 先筛出$<128$的质数,很少,打个表即可 然后钦定一个质数最大,不断替换即可(丢进大根堆里面,然后取出一个,替换在丢进去即可) 具体来说,设一个四元组$[t,x,y,z]$表示当前 ...

  3. BZOJ.2428.[HAOI2006]均分数据(随机化贪心/模拟退火)

    题目链接 模拟退火: 模拟退火!每次随机一个位置加给sum[]最小的组. 参数真特么玄学啊..气的不想调了(其实就是想刷刷最优解) 如果用DP去算好像更准.. //832kb 428ms #inclu ...

  4. 【BZOJ 3569】DZY Loves Chinese II 随机化+线性基

    用到一个结论——[先建树,再给每个非树边一个权值,每个树边的权值为覆盖他的非树边的权值的异或和,然后如果给出的边存在一个非空子集异或和为0则不连通,否则连通](必须保证每条边的出现和消失只能由自己产生 ...

  5. BZOJ 3786: 星系探索 [伪ETT]

    传送门 数据,标程 题意: 一颗有根树,支持询问点到根路径权值和,子树加,换父亲 欧拉序列怎么求路径权值和? 一个点的权值只会给自己的子树中的点贡献,入栈权值正出栈权值负,求前缀和就行了! 和上题一样 ...

  6. BZOJ 3729: Gty的游戏 [伪ETT 博弈论]【学习笔记】

    题意: 给定一棵有根树,每个节点有一些石子,每次可以将不多于k的石子移动到父节点 修改一个点的石子数,插入一个点,询问某棵子树是否先手必胜 显然是一个阶梯Nim 每次最多取k个,找规律或者观察式子易发 ...

  7. BZOJ.5397.circular(随机化 贪心)

    BZOJ 感觉自己完全没做过环上选线段的问题(除了一个2-SAT),所以来具体写一写qwq. 基本完全抄自remoon的题解qwq... (下标从\(0\sim m-1\)) 拆环为链,对于原线段\( ...

  8. BZOJ 2428 JZYZOJ1533 : [HAOI2006]均分数据 模拟退火 随机化

    http://www.lydsy.com/JudgeOnline/problem.php?id=2428 http://172.20.6.3/Problem_Show.asp?id=1533 http ...

  9. bzoj 2428: [HAOI2006]均分数据 随机化

    2428: [HAOI2006]均分数据 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...

随机推荐

  1. Extract local angle of attack on wind turbine blades

    Extract local angle of attack on wind turbine blades Table of Contents 1. Extract local angle of att ...

  2. 爬楼梯,N级楼梯有多少种走法?

    https://blog.csdn.net/tcpipstack/article/details/45173685 一个人爬楼梯,一步可以迈一级,二级,三级台阶,如果楼梯有N级,要求编写程序,求总共有 ...

  3. 页面加载即执行JQuery的三种方法

    [1]$(function( ){ }): $(function(){ $("#name").click(function(){ //adding your code here } ...

  4. Linux下汇编语言学习笔记71 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  5. [bzoj1582][Usaco2009 Hol]Holiday Painting 节日画画_线段树

    Holiday Painting 节日画画 bzoj-1582 Usaco-2009 Hol 题目大意:给定两个n*m的01网格图.q次操作,每次将第二个网格图的子矩阵全部变成0或1,问每一次操作后两 ...

  6. Eclipse创建Maven多模块工程

    一.创建父项目 [New]->[Maven Project] 在弹出界面中选择[Create a simple project...] 二.创建子项目 选中刚建的父项目,在弹出菜单中点击[New ...

  7. 用JQuery实现选中select里面的option显示对应的div

    HTML: <select name=""  onchange="select(this)"> <option value="1&q ...

  8. iOS xmpp协议实现聊天之openfire的服务端配置(二)

    本篇主要说一下怎样利用命令行来正确配置MySql. 首先打开终端: 1.为mysql起一个别名 alias mysql=/usr/local/mysql/bin/mysql 2.创建mysql的管理员 ...

  9. ubuntu 必備

    1.切换到Ubuntu gnome 经典桌面注销unity桌面环境,然后选择登录环境为“经典桌面”即可进入.若是你喜欢Unity,可是你的显卡不给力3D不支持,怎么办呢?安装Unity-2D:sudo ...

  10. xcode执行后没看到输出的解决的方法

    今天刚在虚拟机中的mac苹果里安装xcode.然后開始看Objective-C. 安装完后由于有默认的代码输出Hello world! ,所以就尝试执行了一发: 可惜没看到输出在哪,尼玛.还以为刚開始 ...