题目链接:http://poj.org/problem?id=2653

Time Limit: 3000MS Memory Limit: 65536K

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 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.

题意:

给出n根细木棍的坐标,每次按顺序放到指定坐标位置,这样会导致一些后放的木棍压倒前面的木棍;

求最后那些木棍没有被压住。

题解:

刚开始我是每输入第i跟木棍,就遍历1 ~ i-1的木棍,看看他们有没有被压住,但这样最后TLE了;

看Dis里说,先全部输入,然后枚举,对第i根木棍,遍历i+1 ~ n的木棍,一旦出现压住i的,就标记并且跳出;

明明感觉这样不T很不科学,但就是AC了……奇怪……

AC代码:

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std; const double eps = 1e-; struct Point{
double x,y;
Point(double tx=,double ty=):x(tx),y(ty){}
};
typedef Point Vctor; //向量的加减乘除
Vctor operator + (Vctor A,Vctor B){return Vctor(A.x+B.x,A.y+B.y);}
Vctor operator - (Point A,Point B){return Vctor(A.x-B.x,A.y-B.y);}
Vctor operator * (Vctor A,double p){return Vctor(A.x*p,A.y*p);}
Vctor operator / (Vctor A,double p){return Vctor(A.x/p,A.y/p);} int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return (x<)?(-):();
}
bool operator == (Point A,Point B){return dcmp(A.x-B.x)== && dcmp(A.y-B.y)==;} double Cross(Vctor A,Vctor B){return A.x*B.y-A.y*B.x;} //判断线段是否规范相交
bool SegmentProperIntersection(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)< && dcmp(c3)*dcmp(c4)<;
} int n;
struct Seg{
Point a,b;
bool pressed;
}seg[];
int main()
{
while(scanf("%d",&n) && n!=)
{
for(int i=;i<=n;i++)
{
scanf("%lf%lf%lf%lf",&seg[i].a.x,&seg[i].a.y,&seg[i].b.x,&seg[i].b.y);
seg[i].pressed=;
} for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(SegmentProperIntersection(seg[i].a,seg[i].b,seg[j].a,seg[j].b))
{
seg[i].pressed=;
break;
}
}
} printf("Top sticks: ");
for(int i=,cnt=;i<=n;i++)
{
if(seg[i].pressed) continue;
if(cnt!=) printf(", ");
printf("%d",i);
cnt++;
}
printf(".\n");
}
}

POJ 2653 - Pick-up sticks - [枚举+判断线段相交]的更多相关文章

  1. POJ 2653 Pick-up sticks(判断线段相交)

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7699   Accepted: 2843 De ...

  2. POJ 1066 - Treasure Hunt - [枚举+判断线段相交]

    题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K Description Archeologist ...

  3. POJ 3304 Segments (叉乘判断线段相交)

    <题目链接> 题目大意: 给出一些线段,判断是存在直线,使得该直线能够经过所有的线段.. 解题思路: 如果有存在这样的直线,过投影相交区域作直线的垂线,该垂线必定与每条线段相交,问题转化为 ...

  4. 【POJ 2653】Pick-up sticks 判断线段相交

    一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...

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

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7857   Accepted: 3247 Des ...

  6. POJ2653 Pick-up sticks 判断线段相交

    POJ2653 判断线段相交的方法 先判断直线是否相交 再判断点是否在线段上 复杂度是常数的 题目保证最后答案小于1000 故从后往前尝试用后面的线段 "压"前面的线段 排除不可能 ...

  7. POJ 2826 An Easy Problem? 判断线段相交

    POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...

  8. POJ_2653_Pick-up sticks_判断线段相交

    POJ_2653_Pick-up sticks_判断线段相交 Description Stan has n sticks of various length. He throws them one a ...

  9. POJ_1066_Treasure Hunt_判断线段相交

    POJ_1066_Treasure Hunt_判断线段相交 Description Archeologists from the Antiquities and Curios Museum (ACM) ...

随机推荐

  1. instsrv.exe srvany.exe启动服务

    1.通过注册表注册服务 private static readonly string regpath = @"SYSTEM\CurrentControlSet\Services\Consul ...

  2. 谈谈入门iOS的经验吧

    前言 近期忙完项目比較闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助.博主非科班出身,一些计算机术语上的不专业欢迎大家指正. 我是学微电子的.大四的时候找了一家深圳的专业对口的 ...

  3. VMware Playerでの仮想マシン起動エラー

    Windows Updateすると.翌日VMware Playerの仮想マシン起動時に 「この仮想マシンを構成済み設定でパワーオンするのに十分な物理メモリがありません.」 のエラーとなることが時々あり ...

  4. [AX2012]代码更改默认财务维度

    在前文(http://www.cnblogs.com/duanshuiliu/p/3243048.html)最后演示了如何使用代码更改默认财务维度,那段代码模拟了创建各数据表记录的过程,实际上AX提供 ...

  5. LHC大神问的矩阵转置问题

    数学中线性代数中提到的矩阵转置,其实在我们的业务场景中也有需要的地方,比如LHC大神问到的这个问题 那么如何进行行列转换呢? 代码如下: <?php $array=array( '部门1'=&g ...

  6. My Apple Developer Library Catalog

    Objective-C & Memory Management:Programming with Objective-CConcepts in Objective-C ProgrammingM ...

  7. 【安全开发】Android安全编码规范

    申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...

  8. Synchronizing Threads and GUI in Delphi application

    Synchronizing Threads and GUI   See More About delphi multithreading tthread class user interface de ...

  9. DexArchiveBuilderException

    出现这个问题大概是因为版本资源问题 比如把TextView  改为CompatTextView 解决方法一: 在项目的build.gradle文件中查看自己导入的依赖,看看是否有重复的,如果有的话删除 ...

  10. N76E003系统时钟

    系统时钟源N76E003共有3种系统时钟源,包括: 内部高速/低速振荡器.外部输入时钟.它们每一个都可以作为N76E003的系统时钟源.开启不同的时钟源可能会影响到多功能引脚P3.0/XIN .内部振 ...