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. 基于Spring Cloud和Netflix OSS构建微服务,Part 2

    在上一篇文章中,我们已使用Spring Cloud和Netflix OSS中的核心组件,如Eureka.Ribbon和Zuul,部分实现了操作模型(operations model),允许单独部署的微 ...

  2. php+apache+mysql的安装

    1.LAMP的安装顺序问题,现在是默认安装好了Linux系统,我的版本是Ubuntu 12.04.一般来说比较建议的顺序是Mysql Apache 最后安装PHP,在我实践下来 Apache和Mysq ...

  3. ECMA script 6的新特性

    简单介绍下ES6的新特性: (1)箭头操作符 :简化了函数的书写 (2)类的支持:引入了class关键字,对象的创建,继承更加直观,父类方法的调用,实例化,构造函数等概念更加形象化. (3)增强的对象 ...

  4. maridb安装审计audit插件

    1.下载插件 https://mariadb.com/kb/en/mariadb-audit- plugin/ 比较新的mariadb版本audit插件直接内嵌在版本里,可以直接安装 INSTALL ...

  5. 光环国际的PRINCE2培训时间

    一.光环国际的PRINCE2课程安排培训方式:    小班授课,50人为限;   全国网址直播课程,覆盖各个地区学员    精读原理配合独家开发大量实际案例研讨;    从商业战略角度解析PRINCE ...

  6. 【C语言】printf()函数详解

    printf函数称为格式输出函数,其关键字最末一个字母f即为"格式"(format)之意.其功能是按用户指定的格式,把指定的数据显示到显示器屏幕上.在前面的例题中我们已多次使用过这 ...

  7. Laravel查询构造器的使用方法整理

    1.结果集 1.1从一张表获取所有行,get方法获取所有行 $users = DB::table('users')->get(); 获取列的值 foreach ($users as $user) ...

  8. 老李分享:使用 Python 的 Socket 模块开发 UDP 扫描工具

    老李分享:使用 Python 的 Socket 模块开发 UDP 扫描工具 poptest是业内唯一的测试开发工程师培训机构,测试开发工程师主要是为测试服务开发测试工具,在工作中要求你做网络级别的安全 ...

  9. 手机自动化测试:appium源码分析之bootstrap七

    手机自动化测试:appium源码分析之bootstrap七   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest测试 ...

  10. 老李分享:大数据测试之HDFS文件系统

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-845052 ...