Jack Straws(poj 1127) 两直线是否相交模板
Description
Input
When n=0,the input is terminated.
There will be no illegal input and there are no zero-length straws.
Output
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) 两直线是否相交模板的更多相关文章
- Jack Straws(POJ 1127)
		
原题如下: Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5555 Accepted: 2536 ...
 - Jack Straws POJ - 1127 (简单几何计算 + 并查集)
		
In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table ...
 - Jack Straws POJ - 1127 (几何计算)
		
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5428 Accepted: 2461 Descr ...
 - poj 1127:Jack Straws(判断两线段相交 + 并查集)
		
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2911 Accepted: 1322 Descr ...
 - poj 1127(直线相交+并查集)
		
Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" ...
 - poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)
		
Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...
 - TOJ1840: Jack Straws 判断两线段相交+并查集
		
1840: Jack Straws Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Submit: 1 ...
 - POJ - 1127 Jack Straws(几何)
		
题意:桌子上放着n根木棍,已知木棍两端的坐标.给定几对木棍,判断每对木棍是否相连.当两根木棍之间有公共点或可以通过相连的木棍间接的连在一起,则认为是相连的. 分析: 1.若线段i与j平行,且有部分重合 ...
 - poj1127 Jack Straws(线段相交+并查集)
		
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Jack Straws Time Limit: 1000MS Memory L ...
 
随机推荐
- scrapy 安装流程和启动
			
#Windows平台 1. pip3 install wheel #安装后,便支持通过wheel文件安装软件,wheel文件官网:https://www.lfd.uci.edu/~gohlke/pyt ...
 - c#按照回车换行符分割字符串
			
string str="aaa\r\nbbscccjdddseee"; string[] sArray=str.Split(new char[2] {'\r','\n'}); 和用 ...
 - (转)android权限(permission)大全
			
文章转载自:http://blog.csdn.net/hai_qing_xu_kong/article/details/24265533 1.android.permission.WRITE_USER ...
 - 希尔排序和归并排序(java实现)
			
希尔排序 希尔排序算法实际上是一种特殊的插入排序,由DL.Shell于1959年提出而得名. 算法思想:希尔排序使数组中任意间隔为h的元素都是有序的,这些数组称为h有序数组,对于每个h,按插入排序进行 ...
 - 来看看N多设计师笔下的Spider Man
			
很多电影在大获成功后,其中的人物都成了火热的IP,漫威的各类超级英雄就是个很好的例子,今天突发奇想看看各种漫画人物在插画师手中同一人物会有什么样的不同,所以以蜘蛛侠为主题,搜集了很多插画师笔下的蜘蛛侠 ...
 - Python之路(第三篇):Python基本数据类型字符串(二)
			
一.基本数据类型1.字符串 str字符串方法介绍(二)a --expandtabs( ) expandtabs( ) 把字符串中的 tab 符号('\t')转为空格参数默认为8,注意字符串原有的空格也 ...
 - default(T) 和 typeof 和 GetType()
			
一.default(T) 在泛型编成中如果不限制T类型参数是值类型或引用类型的话 你程序内部可能会出现错误,因为值类型不允许NULL.所以default用来获取一个类型的默认值,对于值类型得到new ...
 - sql2005性能优化(在32位系统上突破2G内存使用量的方法) .
			
转载自http://blog.csdn.net/soldierluo/article/details/6589743 服务器磁盘为(SAS)IBM组成RAID0+1,SQL2K5只识别4G内存,实际只 ...
 - Tomcat优化方案
			
摘自网络: 调优方案分类: 1,外部环境调优 2,自身调优 --------------------------------------------------- 外部环境调优: 1, JAVA虚拟机 ...
 - Prism-超轻量的开源框架
			
http://msdn.microsoft.com/en-us/library/ff648465.aspx prism 是微软模式与实践小组开发的一个进行MVVM模式开发,其中使用依赖注入等一些方法将 ...