线段相交问题(例题:POJ2653)

博客介绍了如何判断线段是否相交,以解决POJ2653比赛题目。通过分析输入输出样例,提供思路和参考代码,解释了在大量输入情况下如何高效处理。
摘要由CSDN通过智能技术生成

判断线段是否相交

判断线段是否相交问题,依然见刘汝佳紫书。

// 每条线段的两个端点都在另一条线段两侧(叉积符号不同)
// a1,a2为一条线段,b1,b2为另一条线段
bool SegProInt(Point a1,Point a2,Point b1,Point b2) {
   
	double c1 = Cross(a2-a1,b1-a1), c2 = Cross(a2-a1,b2-a1),
		   c3 = Cross(b2-b1,a1-b1), c4 = Cross(b2-b1,a2-b1);
	return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}

// 允许端点处相交,则需要判断端点是否在线段上,判断函数如下
// 判断p是否在线段a1,a2上
bool OnSegment(Point p,Point a1,Point a2) {
   
	return dcmp(Cross(a1-p,a2-p))==0 && dcmp(Dot(a1-p,a2-p))<0;
}

Pick-up sticks

Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 15567 Accepted: 5880

Description

Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. Stan sticks are very, very thin such that their thickness can be neglected.

Input

Input consists of a number of cases. The data for each case start with 1 <= n <= 100000, the number of sticks for this case. The following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. The sticks are listed in the order in which Stan has thrown them. You may assume that there are no more than 1000 top sticks. The input is e

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值