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 ended by the case with n=0. This case should not be processed.

Output

For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should be listed in order in which they were thrown.

The picture to the right below illustrates the first case from input.

Sample Input

5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0

Sample Output

Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.

Hint

Huge input,scanf is recommended.
此题是我最讨厌的一类题,tle到我生活不能自理,看了题解后然后就开始wa,最后把之前的tle代码揪出来改了就ac了。。
线段覆盖问题,算最后没有被覆盖的线段就行了
先快速排斥试验,然后跨立试验。
快速排斥试验:
max(u.a.x,u.b.x)<min(v.a.x,v.b.y)
&&max(v.a.x,v.b.x)<min(u.a.x,u.b.x)
       &&max(u.a.y,u.b.y)<min(v.a.y,v.b.y)
       &&max(v.a.y,v.b.y)<min(u.a.y,u.b.y)
跨立试验:
double mul(point p,point u,point v)
{
    return (u.x-v.x)*(p.y-u.y)-(u.y-v.y)*(p.x-u.x);
}
mul(u.a,v.a,v.b)*mul(u.b,v.a,v.b)<=0&&mul(v.a,u.a,u.b)*mul(v.b,u.a,u.b)<=0
刚开始自己想的一个方法(有点慢):
判断两线段是否相交有两种情况:
1:一条线的端点在另一条上;
2:两条线的端点分别在另一条的两侧
这个不需要快速排斥试验,所以很有可能tle。。。。
    if(mul(u.a,v.a,v.b)*mul(u.b,v.a,v.b)<0&&mul(v.a,u.a,u.b)*mul(v.b,u.a,u.b)<0)return 1;
    if(mul(u.a,v.a,v.b)==0&&(u.a.x-v.a.x)*(u.a.x-v.b.x)<=0&&(u.a.y-v.a.y)*(u.a.y-v.b.y)<=0)return 1;
    if(mul(u.b,v.a,v.b)==0&&(u.b.x-v.a.x)*(u.b.x-v.b.x)<=0&&(u.b.y-v.a.y)*(u.b.y-v.b.y)<=0)return 1;
    if(mul(v.a,u.a,u.b)==0&&(v.a.x-u.a.x)*(v.a.x-u.b.x)<=0&&(v.a.y-u.a.y)*(v.a.y-u.b.y)<=0)return 1;
    if(mul(v.b,u.a,u.b)==0&&(v.b.x-u.a.x)*(v.b.x-u.b.x)<=0&&(v.b.y-u.a.y)*(v.b.y-u.b.y)<=0)return 1;
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f; struct point{
double x,y;
};
struct line{
point a,b;
}l[N]; bool out[N];//如果线段有交点,先放的就out double mul(point p,point u,point v)
{
return (u.x-v.x)*(p.y-u.y)-(u.y-v.y)*(p.x-u.x);
}
bool acoss(line u,line v)
{
if(max(u.a.x,u.b.x)<min(v.a.x,v.b.y)
&&max(v.a.x,v.b.x)<min(u.a.x,u.b.x)
&&max(u.a.y,u.b.y)<min(v.a.y,v.b.y)
&&max(v.a.y,v.b.y)<min(u.a.y,u.b.y))return ;
if(mul(u.a,v.a,v.b)*mul(u.b,v.a,v.b)<=&&mul(v.a,u.a,u.b)*mul(v.b,u.a,u.b)<=)return ;
/* if(mul(u.a,v.a,v.b)==0&&(u.a.x-v.a.x)*(u.a.x-v.b.x)<=0&&(u.a.y-v.a.y)*(u.a.y-v.b.y)<=0)return 1;
if(mul(u.b,v.a,v.b)==0&&(u.b.x-v.a.x)*(u.b.x-v.b.x)<=0&&(u.b.y-v.a.y)*(u.b.y-v.b.y)<=0)return 1;
if(mul(v.a,u.a,u.b)==0&&(v.a.x-u.a.x)*(v.a.x-u.b.x)<=0&&(v.a.y-u.a.y)*(v.a.y-u.b.y)<=0)return 1;
if(mul(v.b,u.a,u.b)==0&&(v.b.x-u.a.x)*(v.b.x-u.b.x)<=0&&(v.b.y-u.a.y)*(v.b.y-u.b.y)<=0)return 1;*/
return ;
}
int main()
{
int n;
while(~scanf("%d",&n),n){
memset(out,,sizeof(out));
for(int i=;i<=n;i++)
scanf("%lf%lf%lf%lf",&l[i].a.x,&l[i].a.y,&l[i].b.x,&l[i].b.y);
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(acoss(l[i],l[j]))
{
out[i]=;
break;
}
}
}
bool flag=;
for(int i=;i<=n;i++)
{
if(!out[i])
{
if(flag==)
{
printf("Top sticks: %d",i);
flag=;
}
else printf(", %d",i);
}
}
printf(".\n");
}
return ;
}

poj2653线段相交判断的更多相关文章

  1. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

  2. POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)

    Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1243   Accepted: 524 D ...

  3. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

  4. POJ 3304 Segments (直线和线段相交判断)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 2316 Descript ...

  5. 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)

    转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...

  6. ACM1558两线段相交判断和并查集

    Segment set Problem Description A segment and all segments which are connected with it compose a seg ...

  7. POJ 1066 Treasure Hunt(线段相交判断)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4797   Accepted: 1998 Des ...

  8. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  9. poj 2653 (线段相交判断)

    http://poj.org/problem?id=2653 Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submis ...

随机推荐

  1. virtual dom的实践

    最近基于virtual dom 写了一个小框架-aoy. aoy是一个轻量级的mvvm框架,基于Virtual DOM.虽然现在看起来很单薄,但我做了完善的单元测试,可以放心使用.aoy的原理可以说和 ...

  2. C#全局鼠标键盘Hook

    原文出自:http://www.cnblogs.com/iEgrhn/archive/2008/02/17/1071392.html using System; using System.Collec ...

  3. WPF中MeasureOverride ArrangeOverride 的理解

    1. Measure Arrange这两个方法是UIElement的方法 MeasureOverride ArrangeOverride这两个方法是FrameworkElement的方法,Framew ...

  4. node.js报错throw err; // Rethrow non-MySQL errors e:\serverTest\node_modules\mysql\lib\protocol\Parser.js:79 解决方法

    今天在用node+angular做后台时,需要使用session保存登陆状态的时候,遇到了此问题,问题直译为非mysql问题,我也在后台取到的登陆用户名和密码,确实不是数据库问题.最后发现在使用ses ...

  5. Spring初识(通过小实例清晰认识Spring)

    1.spring架构: spring是J2EE应用程序框架,是轻量级的IoC和AOP的容器框架,主要是针对javaBean的生命周期进行管理的轻量级容器,可以单独使用,也可以和Struts框架,iba ...

  6. OpenStack及其构成简介

    新的一年新的开始,突然想学习下Openstack,之前了解过很多,但是想系统的学习一下,第一次写博客,只想把学到的东西记录下来加深印象,如有写的不好的地方请多多见谅.下面开门见山. 1.What is ...

  7. Xshell连接本地 Virtualbo Ubuntu

    1.打开Virtualbox软件,启动ubuntu虚拟机. Ctrl + Alt + T 打开终端输入一下命令: sudo apt-get update 然后安装ssh 输入:sudo apt-get ...

  8. Java版权信息之Jautodoc

    Java项目开发中,常常需要在编码文件上面加上一些版权声明或者类注释,如果文件很多,手工去添加或者修改,会很麻烦.可以利用工具满足我们的要求.一.版权声明可以使用Jautodoc.将jautodoc的 ...

  9. Entity Framework快速入门--IQueryable与IEnumberable的区别

    IEnumerable接口 公开枚举器,该枚举器支持在指定类型的集合上进行简单迭代.也就是说:实现了此接口的object,就可以直接使用foreach遍历此object: IQueryable 接口 ...

  10. linux awk 命令详解

    awk是一个非常棒的数字处理工具.相比于sed常常作用于一整行的处理,awk则比较倾向于将一行分为数个"字段"来处理.运行效率高,而且代码简单,对格式化的文本处理能力超强.先来一个 ...