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 ;
}
 

最新文章

  1. 利用mysql查询总数据条数,再php处理数据转出数组,生成随机返回到页面,可以做成刷新页面,出现不同的内容
  2. .Net WinForm下配置Log4Net(总结不输出原因)
  3. 分享一个批量导出当前实例下的所有linkedserver脚本
  4. 实用js代码大全
  5. Yii2 使用八 使用scenarios
  6. 使用jquery的delay方式模拟sleep
  7. HTML5 - 使用JavaScript控制&lt;audio&gt;音频的播放
  8. 手把手教你Linux服务器集群部署.net网站 - 让MVC网站运行起来
  9. 将url转化成对象
  10. MySql和Hibernate中关于cascade的用法
  11. 转:Unity3D的四种坐标系
  12. jQuery滑动并响应事件
  13. Oracle 卸载 不干净
  14. Windows 7硬盘安装CentOS 6.4 双系统 (WIN7硬盘安装Linux(Fedora 16,CentOS 6.2,Ubuntu 12.04))
  15. jquery.cookie.js 的配置
  16. HTML 5 服务器发送事件、Input 类型、表单元素、表单属性
  17. sqlite ef6
  18. 【JavaScript函数】
  19. 3.数码相框-通过freetype库实现矢量显示
  20. WEB前端 HTML

热门文章

  1. 引入flash
  2. c#多线程下的进程同步SignalAndWait 使用简单说明
  3. eclipse Tomcat和 MYSQL JAVA web新手开发示例--登录界面连接数据库
  4. JavaScript获取DOM对象的几种方式
  5. OpenGL3D图形、旋转、纹理、键盘移动、光照、滤波、透明(完整) 转自http://www.cnblogs.com/tiandsp/archive/2012/01/23/2329049.html
  6. poj 2785 让和为0 暴力&amp;二分
  7. Python-多线程之消费者模式和GIL全局锁
  8. C#程序如何以管理员身份运行
  9. 看看用PS来转基因的动物,居然很欢乐!!
  10. tmp下莫名其妙生成root权限的缓存文件