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. pyvcf 模块

    最近一直在处理samtools freebayes gatk 产生的snp数据, 结果文件都是vcf,于是自己就写了相应的类,但是总是不够完善. 海宝推荐这个模块,他都推荐了 我还抱着我那烂代码不放干 ...

  2. css透明度的设置 (兼容所有浏览器)

    一句话搞定透明背景! .transparent_class { filter:alpha(opacity=); -moz-opacity:0.5; -khtml-opacity: 0.5; opaci ...

  3. webStorm快捷键总结

    Ctrl+Shift+a:快速查找使用编辑器所有功能1.左侧栏目录显影:Ctrl+Shift+F122.文件模板配置:File>Settings>Editor>File and Co ...

  4. 关于JSP的C标签之forEach循环分隔符

    页面中可能说出现在forEach循环中间需要出力分隔符的问题, 比如: 小明 1年级,小王 2年级, 小张 3年级(循环单位是 ${bean.name} ${bean.class}) 此时的逗号出力, ...

  5. hdu3072 强连通+最小树形图

    题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...

  6. 英语语法最终珍藏版笔记-18what 从句的小结

    what 从句的小结 1.意思是“所….的事/物”, 相当于the thing(s) that…, that which…, 或those which… 可以用于以下情况: (1) 引导主语从句.如: ...

  7. JS的prototype的共享机制分析

    function Super(){ } Super.prototype.aaa=[1,2,3]; Super.prototype.bbb=1; function Sub(){ Super.call(t ...

  8. 如何生成a1,a2,a3,a4这样的变量名

    var num=6; function Girl(beautifulScore){ this.beautifulScore=beautifulScore; } var girls=[]; for (v ...

  9. MSSQL中建立分区表(转载备忘)

    转载自CSDN地址:http://bbs.csdn.net/topics/330087045 SQL Server 2005 分区表实践——建立分区表(partition table) 问题:有一个订 ...

  10. MySQLdb

    MySQLdb的使用 #mysql> create table `account`( # -> `acctid` int(11) default null comment 'XXXX', ...