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 ...
随机推荐
- (实用篇)PHP页面跳转到另一个页面的方法总结
一.用HTTP头信息 也就是用PHP的header函数.PHP里的header函数的作用就是向浏览器发出由HTTP协议规定的本来应该通过WEB服务器的控制指令,例如声明返回信息的类型("C ...
- 单元测试--四则运算2程序(c++)
源代码: //2016 3.6 Cheng Qiqin //四则运算改进 #include <iostream> #include<ctime> #include<cst ...
- form的onsubmit事件--表单提交前的验证最佳实现方式
今天遇到了一个问题,页面中include了很多的公共页面(都是没有form的),并且里面好多的地方都是自行提交的(页面中加入一个type=“submit”域,然后js中写入sumbit.click来执 ...
- smartUpload组件单文件下载
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...
- scala言语基础学习十二
- poj3159 最短路(差分约束)
题意:现在需要分糖果,有n个人,现在有些人觉得某个人的糖果数不能比自己多多少个,然后问n最多能在让所有人都满意的情况下比1多多少个. 这道题其实就是差分约束题目,根据题中给出的 a 认为 b 不能比 ...
- 【NOIP2010】关押罪犯
一开始看错题了,然后怎么想都想不明白--原题: S 城现有两座监狱,一共关押着 N 名罪犯,编号分别为 1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲 ...
- java编程之:生成rsa密钥
通过openssl工具生成RSA的公钥和私钥(opnssl工具可在互联网中下载到,也可以点此下载无线接口包,里面包含此工具) 打开openssl文件夹下的bin文件夹,执行openssl.exe文件: ...
- bootstrap源码里的function加上了+号
一般看JQuery插件里的写法是这样的 (function($) { //... })(jQuery); 今天看到bootstrap的javascript组件是这样写的 !function( $ ){ ...
- windows API
Process and Thread Functions https://msdn.microsoft.com/en-us/library/windows/desktop/ms684847(v=vs. ...