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

  1. 7
  2. 1 6 3 3
  3. 4 6 4 9
  4. 4 5 6 7
  5. 1 4 3 5
  6. 3 5 5 5
  7. 5 2 6 3
  8. 5 4 7 2
  9. 1 4
  10. 1 6
  11. 3 3
  12. 6 7
  13. 2 3
  14. 1 3
  15. 0 0
  16.  
  17. 2
  18. 0 2 0 0
  19. 0 0 0 1
  20. 1 1
  21. 2 2
  22. 1 2
  23. 0 0
  24.  
  25. 0

Sample Output

  1. CONNECTED
  2. NOT CONNECTED
  3. CONNECTED
  4. CONNECTED
  5. NOT CONNECTED
  6. CONNECTED
  7. CONNECTED
  8. CONNECTED
  9. CONNECTED
  10.  
  1.  
  1. 给你 n 个木棍, 每根木棍 4 个坐标, 给你两个编号, 问这两个编号的木棍是否相交(可以间接相交)
  2.  
  1.  
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8. #define N 20
  9. const double eps=1e-;
  10.  
  11. struct Point
  12. {
  13. int x, y;
  14. };
  15.  
  16. struct node
  17. {
  18. Point a;
  19. Point b;
  20. }P[N];
  21.  
  22. int G[N][N], n;
  23.  
  24. /**--------- 判断两线段相交 模板 ------------**/
  25. int Judge(int x, int y)
  26. {
  27. Point a, b, c, d;
  28. a = P[x].a, b = P[x].b;
  29. c = P[y].a, d = P[y].b;
  30. if ( min(a.x, b.x) > max(c.x, d.x) ||
  31. min(a.y, b.y) > max(c.y, d.y) ||
  32. min(c.x, d.x) > max(a.x, b.x) ||
  33. min(c.y, d.y) > max(a.y, b.y) ) return ;
  34. double h, i, j, k;
  35. h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
  36. i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
  37. j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
  38. k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
  39. return h * i <= eps && j * k <= eps;
  40. }
  41.  
  42. void Slove()
  43. {
  44. int i, j, k;
  45.  
  46. for(i=; i<=n; i++)
  47. for(j=i+; j<=n; j++)
  48. {
  49. if(Judge(i, j))
  50. G[i][j] = G[j][i] = ;
  51. }
  52.  
  53. for(k=; k<=n; k++)
  54. for(i=; i<=n; i++)
  55. for(j=; j<=n; j++)
  56. {
  57. if(G[i][k] && G[k][j])
  58. G[i][j] = ;
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. while(scanf("%d", &n), n)
  65. {
  66. int i, u, v;
  67.  
  68. for(i=; i<=n; i++)
  69. scanf("%d%d%d%d", &P[i].a.x, &P[i].a.y, &P[i].b.x, &P[i].b.y);
  70.  
  71. memset(G, , sizeof(G));
  72. Slove();
  73. while(scanf("%d%d", &u, &v), u+v)
  74. {
  75. if(G[u][v] || u==v) printf("CONNECTED\n");
  76. else printf("NOT CONNECTED \n");
  77. }
  78. }
  79.  
  80. return ;
  81. }
 

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. B+树与B-树

    前面已经介绍过B-树,接下来,我们主要介绍一下B+树. 1.B+树的概念 B+树是应文件系统所需而生的一种B-树和变形树.一棵m阶B+树和m阶的B-树的差异在于: (1)有n棵子树的结点中含有n个关键 ...

  2. hdu 1757 (矩阵快速幂) 一个简单的问题 一个简单的开始

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * ...

  3. IDEA 的主题设置

    1.主题设置(Appearance& Behavior) 补充1:设置编辑区的主题 (1)IDEA提供了两个编辑区的主题,如下所示 (2)如果想要更多的主题效果,可以到 http://www. ...

  4. nodejs 数字字节转换操作

    function number2Bytes(i) { var arr = new Int32Array(1); arr[0] = 0; var buf = Buffer.from(arr.buffer ...

  5. 20180613更新 leetcode刷题

    最近就是忙工作项目 工作间隙就刷了刷LEETCODE 所以没啥更新 // 1111111.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #i ...

  6. PHP连接SQLServer2012两例

    首先放上 PHP连接SQLServer的驱动下载地址 http://php.net/manual/zh/ref.pdo-sqlsrv.php 另外PHP for IIS管理工具 大家可以自己搜索一下 ...

  7. OneZero第三周第二次站立会议(2016.4.5)

    1. 时间: 13:00--13:15  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  8. 【Linux】DNS服务-BIND基础配置(二)

    BIND简介 现在使用最为广泛的DNS服务器软件是BIND(Berkeley Internet Name Domain),最早有伯克利大学的一名学生编写,现在最新的版本是9,有ISC(Internet ...

  9. java.lang.SuppressWarnings的注解简介

    简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...

  10. tomcat7 安装 windows 服务

    tomcat 可以安装成windows 服务,这样 每次启动就不需要启动tomcat了. 具体配置: 1.修改 service.bat 在行首添加 set "JAVA_HOME=E:\jdk ...