判断线段是否相交
判断线段是否相交问题,依然见刘汝佳紫书。
// 每条线段的两个端点都在另一条线段两侧(叉积符号不同)
// 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