bzoj1173: [Balkan2007]Point
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的更多相关文章
- BZOJ 1176: [Balkan2007]Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 2012 Solved: 896[Submit][St ...
- BZOJ1174: [Balkan2007]Toponyms
1174: [Balkan2007]Toponyms Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 117 Solved: 16[Submit][S ...
- BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )
考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...
- BZOJ 1176([Balkan2007]Mokia-CDQ分治-分治询问)
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MB Submit: 185 Solved: 94 [ Submit] ...
- 【BZOJ1176】[Balkan2007]Mokia/【BZOJ2683】简单题 cdq分治
[BZOJ1176][Balkan2007]Mokia Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=1600 ...
- 1176: [Balkan2007]Mokia
1176: [Balkan2007]Mokia 链接 分析 三维偏序问题,CDQ分治论文题. 代码 #include<bits/stdc++.h> using namespace std; ...
- [BZOJ1176][Balkan2007]Mokia cdq+树状数组
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 3134 Solved: 1395[Submit][S ...
- BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组
BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组 Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加 ...
- BZOJ 1176[Balkan2007]Mokia(CDQ分治)
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 3381 Solved: 1520[Submit][S ...
随机推荐
- Java 使用对话框选择文件并输出到控制台
import java.util.*; import java.io.*; import javax.swing.JFileChooser; public class ReadFileUsingJFi ...
- 十五个最常用Linux命令行 - imsoft.cnblogs
众多Linux管理员在使用Linux的时候会经常使用到很多Linux命令行,其中有绝大部分不是经常使用到的.在本文中主要为大家总结了经常使用的十五个最常用Linux命令行,希望对刚刚接触Linux命令 ...
- poj 1190 生日蛋糕
中文题 题目分析 搜索题,非常好的剪枝 由于深度一定(m),所以使用深度优先搜索,自上而下的设定蛋糕序号,最顶层的为第1层,……,最底层的蛋糕为第m层,很明显满足题目条件的前i层的(从顶层(也就是编号 ...
- 设置drawable图片
google官方建议在textView和imageView挨着的时候,建议使用drawable来显示图片 第一个方法:setCompoundDrawablesWithIntrinsicBounds(D ...
- CentOS 6.2 OpenVPN 搭建
一.yum 安装. 二.下载 easy-rsa 3.0 三.生成根证书.服务器.客户端证书.ta 生成流程: wget -c https://github.com/OpenVPN/easy-rsa/a ...
- linux安装phpredis扩展
1.下载扩展安装包 wget https://github.com/nicolasff/phpredis/downloads 2.解压 tar -zxvf nicolasff-phpredis-2 ...
- 2015GitWebRTC编译实录4
2015.07.17 libg711 编译通过[422/1600 ] CC obj /webrtc/modules/audio_coding/codecs/g711/g711.g711.o[423/1 ...
- leetcode 109 Convert Sorted List to Binary Search Tree ----- java
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
- PHP的一些要点
1.用户评论的内容应当使用htmlspecialchars()函数进行过滤,如htmlspecialchars($_POST['content']);再写入数据库,防止用户评论中含有JS和HTML代码 ...
- SecureCRT注册机使用方法
SecureCRT_7.3注册机激活步骤如下: 1)准备工作 安装好SecureCRT软件, 下载并得到该注册机. 2)保持SecureCRT软件关闭(运行的话会提示你正在运行的,关闭就好). 3)将 ...