Description

In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one without disturbing the other straws. Here, we are only concerned with if various pairs of straws are connected by a path of touching straws. You will be given a list of the endpoints for some straws (as if they were dumped on a large piece of graph paper) and then will be asked if various pairs of straws are connected. Note that touching is connecting, but also two straws can be connected indirectly via other connected straws.

Input

Input consist multiple case,each case consists of multiple lines. The first line will be an integer n (1 < n < 13) giving the number of straws on the table. Each of the next n lines contain 4 positive integers,x1,y1,x2 and y2, giving the coordinates, (x1,y1),(x2,y2) of the endpoints of a single straw. All coordinates will be less than 100. (Note that the straws will be of varying lengths.) The first straw entered will be known as straw #1, the second as straw #2, and so on. The remaining lines of the current case(except for the final line) will each contain two positive integers, a and b, both between 1 and n, inclusive. You are to determine if straw a can be connected to straw b. When a = 0 = b, the current case is terminated.

When n=0,the input is terminated.

There will be no illegal input and there are no zero-length straws.

Output

You should generate a line of output for each line containing a pair a and b, except the final line where a = 0 = b. The line should say simply "CONNECTED", if straw a is connected to straw b, or "NOT CONNECTED", if straw a is not connected to straw b. For our purposes, a straw is considered connected to itself.

Sample Input

7
1 6 3 3
4 6 4 9
4 5 6 7
1 4 3 5
3 5 5 5
5 2 6 3
5 4 7 2
1 4
1 6
3 3
6 7
2 3
1 3
0 0 2
0 2 0 0
0 0 0 1
1 1
2 2
1 2
0 0 0

Sample Output

CONNECTED
NOT CONNECTED
CONNECTED
CONNECTED
NOT CONNECTED
CONNECTED
CONNECTED
CONNECTED
CONNECTED

给你 n 个木棍, 每根木棍 4 个坐标, 给你两个编号, 问这两个编号的木棍是否相交(可以间接相交) 


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; #define N 20
const double eps=1e-; struct Point
{
int x, y;
}; struct node
{
Point a;
Point b;
}P[N]; int G[N][N], n; /**--------- 判断两线段相交 模板 ------------**/
int Judge(int x, int y)
{
Point a, b, c, d;
a = P[x].a, b = P[x].b;
c = P[y].a, d = P[y].b;
if ( min(a.x, b.x) > max(c.x, d.x) ||
min(a.y, b.y) > max(c.y, d.y) ||
min(c.x, d.x) > max(a.x, b.x) ||
min(c.y, d.y) > max(a.y, b.y) ) return ;
double h, i, j, k;
h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
return h * i <= eps && j * k <= eps;
} void Slove()
{
int i, j, k; for(i=; i<=n; i++)
for(j=i+; j<=n; j++)
{
if(Judge(i, j))
G[i][j] = G[j][i] = ;
} for(k=; k<=n; k++)
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
if(G[i][k] && G[k][j])
G[i][j] = ;
}
} int main()
{
while(scanf("%d", &n), n)
{
int i, u, v; for(i=; i<=n; i++)
scanf("%d%d%d%d", &P[i].a.x, &P[i].a.y, &P[i].b.x, &P[i].b.y); memset(G, , sizeof(G));
Slove();
while(scanf("%d%d", &u, &v), u+v)
{
if(G[u][v] || u==v) printf("CONNECTED\n");
else printf("NOT CONNECTED \n");
}
} return ;
}
 

Jack Straws(poj 1127) 两直线是否相交模板的更多相关文章

  1. Jack Straws(POJ 1127)

    原题如下: Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5555   Accepted: 2536 ...

  2. Jack Straws POJ - 1127 (简单几何计算 + 并查集)

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

  3. Jack Straws POJ - 1127 (几何计算)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5428   Accepted: 2461 Descr ...

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

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

  5. poj 1127(直线相交+并查集)

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

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

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

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

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

  8. POJ - 1127 Jack Straws(几何)

    题意:桌子上放着n根木棍,已知木棍两端的坐标.给定几对木棍,判断每对木棍是否相连.当两根木棍之间有公共点或可以通过相连的木棍间接的连在一起,则认为是相连的. 分析: 1.若线段i与j平行,且有部分重合 ...

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

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

随机推荐

  1. 认识Thymeleaf:简单表达式和标签 基础信息

    转载:https://www.cnblogs.com/beyrl-blog/p/6633182.html 本文只适用于不会Java对HTML语言有基础的程序员们,是浏览了各大博客后收集整理,重新编辑的 ...

  2. VS新建API控制器时提示“运行所选代码生成器时出错”

    使用Nuget安装microsoft.entityframeworkcore.tools这个包就行了,安装时注意版本. 根据下图提示应该是新建控制器时用到了这个包,所以安装一下就好了.之前遇到过一次, ...

  3. go 语言实现一个简单的 web 服务器

    学习Go语言的一些感受,不一定准确. 假如发生战争,JAVA一般都是充当航母战斗群的角色.一旦出动,就是护卫舰.巡洋舰.航母舰载机.预警机.电子战飞机.潜艇等等浩浩荡荡,杀将过去.(JVM,数十个JA ...

  4. DevExpress如何实现皮肤的添加及本地化

    DevExpress.XtraBars.Helpers.SkinHelper类允许您填充现有RibbonGalleryBarItem或任意菜单(PopupMenu或BarSubItem)项目对应的De ...

  5. 21.Mysql Server优化

    21.优化Mysql Server21.1 Mysql体系结构概览Mysql由Mysql Server层和存储引擎层组成.Mysql实例由一组后台进程.一写内存块和若干服务线程组成.Mysql后台进程 ...

  6. 1F - A+B for Input-Output Practice (III)

    Your task is to Calculate a + b. Input Input contains multiple test cases. Each test case contains a ...

  7. 28335XINTF的简单使用

    28335 XINTF基本特点 一共有三个外部存储区域:区域0(Zone 0),区域6(Zone 6)和区域7(Zone 7).对应的 访问地址为:Zone 0:0x0000_4000-0x0000_ ...

  8. 大数加法java版

    import java.util.*; import java.math.BigDecimal; public class Numadd{ public static void main(String ...

  9. BZOJ1001或洛谷4001 [BJOI2006]狼抓兔子

    BZOJ原题链接 洛谷原题链接 显然就是求最小割. 而对于一个平面图有结论,最大流=最小割=对偶图最短路. 所以这题可用最大流或是转换为对偶图求最短路,这里我是用的对偶图. 虽然理论上按上界算,这题\ ...

  10. 句子相似度_tf/idf

    import mathfrom math import isnanimport pandas as pd#结巴分词,切开之后,有分隔符def jieba_function(sent): import ...