Description

给出N个三维空间上的点. 问有多少条直线,这些直线上至少有三个点.

Input

第一行给出数字N,N在[4,1000] 下面N行,每行三个数字,用于描述点的坐标,其值在[-10000,10000]

Output

有多少条直线

枚举直线的方向,对每个方向建一个图,若两点间连线在这个方向上则连边,每个至少有三个点的联通块代表一条直线

#include<cstdio>
#include<algorithm>
inline int gcd(int x,int y){
for(int z;y;z=x,x=y,y=z%y);
return x;
}
int n;
struct pos{
int x,y,z;
void fix(){
int g=gcd(gcd(x,y),z);
x/=g;y/=g;z/=g;
if(x!=?x<:y!=?y<:z<)x=-x,y=-y,z=-z;
}
}ps[];
bool operator==(const pos&a,const pos&b){return a.x==b.x&&a.y==b.y&&a.z==b.z;}
bool operator<(const pos&a,const pos&b){return a.x!=b.x?a.x<b.x:a.y!=b.y?a.y<b.y:a.z<b.z;}
pos operator-(pos a,pos b){return (pos){a.x-b.x,a.y-b.y,a.z-b.z};}
struct line{
int a,b;
pos v;
}as[*];
bool operator<(const line&a,const line&b){return a.v<b.v;}
int ap=,ans=;
int es[],enx[],e0[],ep=,ds[],dp=,T,tk[];
int dfs(int w){
int c=;
tk[w]=T;
for(int i=e0[w];i;i=enx[i]){
int u=es[i];
if(tk[u]!=T)c+=dfs(u);
}
return c;
}
void adde(int a,int b){
if(!e0[a])ds[dp++]=a;
if(!e0[b])ds[dp++]=b;
es[ep]=b;enx[ep]=e0[a];e0[a]=ep++;
es[ep]=a;enx[ep]=e0[b];e0[b]=ep++;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%d%d%d",&ps[i].x,&ps[i].y,&ps[i].z);
for(int i=;i<=n;++i){
for(int j=;j<i;++j){
(as[ap++]=(line){i,j,ps[i]-ps[j]}).v.fix();
}
}
std::sort(as,as+ap);
for(int i=,j=;i<ap;){
for(;j<ap&&as[i].v==as[j].v;++j);
for(++T;i<j;++i)adde(as[i].a,as[i].b);
for(int k=;k<dp;++k)if(dfs(ds[k])>=)++ans;
while(dp)e0[ds[--dp]]=;ep=;
}
printf("%d\n",ans);
return ;
}

bzoj1173: [Balkan2007]Point的更多相关文章

  1. BZOJ 1176: [Balkan2007]Mokia

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2012  Solved: 896[Submit][St ...

  2. BZOJ1174: [Balkan2007]Toponyms

    1174: [Balkan2007]Toponyms Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 117  Solved: 16[Submit][S ...

  3. BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )

    考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...

  4. BZOJ 1176([Balkan2007]Mokia-CDQ分治-分治询问)

    1176: [Balkan2007]Mokia Time Limit: 30 Sec   Memory Limit: 162 MB Submit: 185   Solved: 94 [ Submit] ...

  5. 【BZOJ1176】[Balkan2007]Mokia/【BZOJ2683】简单题 cdq分治

    [BZOJ1176][Balkan2007]Mokia Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=1600 ...

  6. 1176: [Balkan2007]Mokia

    1176: [Balkan2007]Mokia 链接 分析 三维偏序问题,CDQ分治论文题. 代码 #include<bits/stdc++.h> using namespace std; ...

  7. [BZOJ1176][Balkan2007]Mokia cdq+树状数组

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 3134  Solved: 1395[Submit][S ...

  8. BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组

    BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组 Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加 ...

  9. BZOJ 1176[Balkan2007]Mokia(CDQ分治)

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 3381  Solved: 1520[Submit][S ...

随机推荐

  1. USB Packet Types

    USB has four different packet types. Token packets indicate the type of transaction to follow, data ...

  2. 阿里云2003服务器VPN搭建[转自阿里云官方论坛]

    VPN可以应用在很多方面,很多公司只是拿它接入公司内部网络,但我们做安全的需要的是利用它做跳板上网(还有提高网速).这篇文章主要是针对这种应用来说的,包括公网VPN的配置. 服务器配置 前奏:关闭防火 ...

  3. JavaScript 编写多线程代码引用Concurrent.Thread.js(转)

    这是一个很简单的功能实现: <script type="text/javascript" src="Concurrent.Thread.js">&l ...

  4. 关于java“配置环境变量”的那些事

    我们刚开始学习java,都会面临编程路上的第一个小怪兽:配环境变量. 网上很多教程给了我们很多的参考,但我们是否有想过为什么要这么配呢?下面我就是想重点探讨一下为什么?并且希望以后你们不但能配,还知道 ...

  5. JS初学之-自定义属性(索引值)

    重点:1.添加索引值的作用:建立匹配.对应的关系. 比如:使每一个按钮对应数组里的每一张图,arrImg[this.index]. 2.不要在for循环的函数里面使用i. 3.添加索引值的方法aBtn ...

  6. AttributeError: 'NoneType' object has no attribute 'bytes' python3.4 win64

    解决方法: easy_install -U pip 详见: https://github.com/pypa/pip/issues/2669

  7. Apahce的虚拟用户认证及server-status页

    一.Apache虚拟用户认证配置 编辑配置文件加入如下内容: <Directory "/www/htdoc/fin"> Options None AllowOverri ...

  8. Android——ListView相关作业(修改版)

    给GridView提供点击按钮添加新数据,单击项目修改,长按删除功能 activity_practise7的layout文件: <?xml version="1.0" enc ...

  9. zoj3261 带权并查集

    题意:有很多颗星球,各自有武力值,星球间有一些联系通道,现在发生战争,有一些联系通道会被摧毁,而一些星球会通过还没有被摧毁的联系通道直接或者间接联系能够联系到的武力值最高的星球求救,如果有多个武力值都 ...

  10. Codeforces Round #339 Div.2 A - Link/Cut Tree

    第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ // ...