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. supermap开发webgis的经验

    SuperMap 开发WebGIS的经验总结 - 综合课件 - 道客巴巴 http://www.doc88.com/p-743552004620.html

  2. Hadoop2.7.3分布式集群安装

    一.依赖文件安装 1.1 JDK 参见博文:http://www.cnblogs.com/liugh/p/6623530.html 二.文件准备 2.1 文件名称 hadoop-2.7.3.tar.g ...

  3. 2017年要学习的JavaScript的顶级框架和主题

    JavaScript的流行促进了一个非常活跃的由相关技术,框架和库组成的生态圈的发展.整个生态圈的多样性和活跃性越来越强,这让许多人变得越来越困惑. 你应该了解些什么技术呢?   我们应该将时间花费在 ...

  4. Modbus通信协议详解

    附:http://www.360doc.com/content/14/0214/13/15800361_352436989.shtml 一.Modbus 协议简介 Modbus 协议是应用于电子控制器 ...

  5. 使用register_shutdown_function触发写日志,使用fastcgi_finish_request提高响应速度

    公司内部的市场管理系统,一直是我一个人维护,最近老是有开发埋怨,内网的账号被人改了密码,账号被解绑了...哈的,错在这还不是一个完整的系统,既没有严格的权限也没有做操作日志呀... 权限现在是准备做在 ...

  6. XJOIWinterCampPrecontest1-P2队列

    2 排队2.1 题目有n 个人打水,第i 个人打水需要ai 的时间.有K 个水龙头,你可以随意安排他们打水的顺序以及使用哪一个水龙头,但是每一时刻每一个水龙头只能有一个人使用且一个人一旦开始打水就不能 ...

  7. 解决vagrant up启动失败,停留在Booting VM...过程的方法

    如图,这种情况是因为没有正确关闭虚拟机导致的,关闭时应在命令行使用vagrant halt 命令,如果直接关机便会出现这种情况. 解决办法:直接启动VirtualBox,并在命令行vagrant ha ...

  8. VB中的GDI编程-1 设备环境DC

    p{ font-size: 15px; } .alexrootdiv>div{ background: #eeeeee; border: 1px solid #aaa; width: 99%; ...

  9. Centos/RHEL上查看主板型号

    老是搞忘记,专门做个记录: [root@media ~]# dmidecode | grep "Product Name" Product Name: To be filled b ...

  10. windows系统System32中各种实用的工具

    工具类 这些工具可以直接打开运行  输入名字就可以调出来了 我还会上传一个java程序,运行后会显示一个界面,直接调用这些工具 1.SnippingTool.exe   截图 2.calc.exe   ...