题意:

有n个木棍,给出木棍的两个端点的x,y坐标,判断其中某两个线段是否连通(可通过其他线段连通)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int big=50000;
int max(int a,int b) {return a>b?a:b;};
int min(int a,int b) {return a<b?a:b;};
int r[15];
struct node{
int x,y;
}p;
struct Line{
node a,b;
}line[15];
int neiji(node a,node b)
{
return a.x*b.x+a.y*b.y;
} int jian(node a,node b,node c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} int findr(int i)
{
if(i!=r[i])
r[i]=findr(r[i]);
return r[i];
}
void unite(int i,int j)
{
int ri=findr(i),rj=findr(j);
r[rj]=ri;
}
int solve(Line m,Line n)
{
if(min(m.a.x,m.b.x)<=max(n.a.x,n.b.x)&&
max(m.a.x,m.b.x)>=min(n.a.x,n.b.x)&&
min(m.a.y,m.b.y)<=max(n.a.y,n.b.y)&&
max(m.a.y,m.b.y)>=min(n.a.y,n.b.y)&&
jian(m.a,m.b,n.a)*jian(m.a,m.b,n.b)<=0&&
jian(n.a,n.b,m.a)*jian(n.a,n.b,m.b)<=0)
return 1;
return 0;
}//跨立实验判断线段相交
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{ for(int i=1;i<=n;i++)
scanf("%d %d %d %d",&line[i].a.x,&line[i].a.y,&line[i].b.x,&line[i].b.y); for(int i=1;i<=n;i++)
r[i]=i; for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)/*并查集检验线段的连通性,注意是两层循环,每个i都将直接与其相连的加入它当前所在的集合*/
{
if(findr(i)==findr(j))continue;
if(solve(line[i],line[j]))
unite(i,j);
} while(1)
{
int a,b;
scanf("%d %d",&a,&b);
if(!a||!b) break;
if(findr(a)==findr(b))
printf("CONNECTED\n");
else
printf("NOT CONNECTED\n");
}
}
return 0;
}

  分析:跨立实验模板+并查集

TTTTTTTTTTTTTT poj 1127 Jack Straws 线段相交+并查集的更多相关文章

  1. [poj 1127]Jack Straws[线段相交][并查集]

    题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...

  2. POJ 1127 Jack Straws (线段相交)

    题意:给定一堆线段,然后有询问,问这两个线段是不是相交,并且如果间接相交也可以. 析:可以用并查集和线段相交来做,也可以用Floyd来做,相交就是一个模板题. 代码如下: #pragma commen ...

  3. poj1127 Jack Straws(线段相交+并查集)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Jack Straws Time Limit: 1000MS   Memory L ...

  4. TZOJ 1840 Jack Straws(线段相交+并查集)

    描述 In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the ta ...

  5. poj 1127:Jack Straws(判断两线段相交 + 并查集)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2911   Accepted: 1322 Descr ...

  6. POJ 1127 Jack Straws(计算几何)

    题目链接 抄的模版,居然1Y了.就是简单的线段相交+并查集. #include <iostream> #include <cstring> #include <cstdi ...

  7. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  8. TOJ1840: Jack Straws 判断两线段相交+并查集

    1840: Jack Straws  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Submit: 1 ...

  9. hdu 1558 线段相交+并查集

    题意:要求相交的线段都要塞进同一个集合里 sol:并查集+判断线段相交即可.n很小所以n^2就可以水过 #include <iostream> #include <cmath> ...

随机推荐

  1. Diameter of Binary Tree

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  2. APP_测试流程(测试点)

    1 APP测试基本流程 1.1流程图 1.2测试周期 测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日),根据项目情况以及版本质量可适当缩短或延长测试时间. 1.3测试资 ...

  3. Python进阶编程 类与类的关系

    类与类的关系 依赖关系 # 依赖关系: 将一个类的类名或者对象传给另一个类的方法中. class Elephant: def __init__(self, name): self.name = nam ...

  4. oracle 安装后参数调整

    关闭11g 新特性 开归档 oracle 11g安装完成需修改:1.关闭审计alter system set audit_trail=none scope=spfile sid='*'; 防止ORA- ...

  5. pc和手机适应js代码

    如果是手机的话跳转到新的地址 <script type="text/javascript"> function IsPC() { var userAgentInfo = ...

  6. Vue中如何插入m3u8格式视频,3分钟学会!

    ​        大家都知道video只支持ogg.webm.MP4格式,但是要是m3u8格式的视频怎么办?最近遇到这个问题在网上找了好多办法都不行,最后找到video.js后才完美解决,所以决定写一 ...

  7. vue项目-axios封装、easy-mock使用

    vue全家桶概括下来就是 项目构建工具(vue-cli) 路由(vue-router) 状态管理(vuex) http请求工具 vue有自己的http请求工具插件vue-resource,但是vue2 ...

  8. python爬去虎扑数据信息,完成可视化

    首先分析虎扑页面数据 如图我们所有需要的数据都在其中![image.png](1)所以我们获取需要的内容直接利用beaitifulsoupui4``` soup.find_all('a',class_ ...

  9. ValueError: day is out of range for month

    日期超出范围. 我当时使用datetime模块生成时间格式数据,手误传错参数导致的结果.所以,好好检查数据就可解决问题. 如下: # 将字符串类型数据转化成时间结构数据# 原想写成如下代码import ...

  10. idea使用问题总结

    一.创建Spring 的配置文件需要加入一个pom.xml 的依赖 <dependency> <groupId>org.springframework</groupId& ...