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.

 
题目大意:在地上抛n条棍子,问有哪几条棍子没有被其他棍子压着。
思路:暴力搜,这题暂时还没有发现什么有效的解法……
有人说You may assume that there are no more than 1000 top sticks.所以换个姿势暴力就不会TLE了……
明明最坏还是得O(n^2)嘛……只要你给我代码还是能卡……比如我的代码……前n-1个线段都不相交,最后一条跨立前n-1个线段,然后每次都要扫到最后,就卡掉了……
除非上面那句话说的是任何时刻而不是最后时刻,嘛没有说清楚这就是出题人的问题了……(在线计算,拿个1000的队列记住那些还没被覆盖,复杂度O(n * 1000))
反正我只是为做模板而已……随便啦这种小事……
 
代码(516MS):
 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const double EPS = 1e-; inline int sgn(double x) {
return (x > EPS) - (x < -EPS);
} struct Point {
double x, y;
Point() {}
Point(double x, double y): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
bool operator < (const Point &rhs) const {
if(y != rhs.y) return y < rhs.y;
return x < rhs.x;
}
Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
Point operator * (const int &b) const {
return Point(x * b, y * b);
}
Point operator / (const int &b) const {
return Point(x / b, y / b);
}
double length() const {
return sqrt(x * x + y * y);
}
Point unit() const {
return *this / length();
}
};
typedef Point Vector; double dist(const Point &a, const Point &b) {
return (a - b).length();
} double across(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
//ret >= 0 means turn left
double cross(const Point &sp, const Point &ed, const Point &op) {
return sgn(across(sp - op, ed - op));
} struct Seg {
Point st, ed;
Seg() {}
Seg(Point st, Point ed): st(st), ed(ed) {}
void read() {
st.read(); ed.read();
}
}; bool isIntersected(Point s1, Point e1, Point s2, Point e2) {
return (max(s1.x, e1.x) >= min(s2.x, e2.x)) &&
(max(s2.x, e2.x) >= min(s1.x, e1.x)) &&
(max(s1.y, e1.y) >= min(s2.y, e2.y)) &&
(max(s2.y, e2.y) >= min(s1.y, e1.y)) &&
(cross(s2, e1, s1) * cross(e1, e2, s1) >= ) &&
(cross(s1, e2, s2) * cross(e2, e1, s2) >= );
} bool isIntersected(Seg a, Seg b) {
return isIntersected(a.st, a.ed, b.st, b.ed);
} /*******************************************************************************************/ const int MAXN = ; Seg s[MAXN];
bool isAns[MAXN];
Point p;
int n; int main() {
while(scanf("%d", &n) != EOF && n) {
memset(isAns, true, sizeof(isAns));
for(int i = ; i < n; ++i) s[i].read();
for(int i = ; i < n; ++i)
for(int j = i + ; j < n; ++j) {
if(isIntersected(s[i], s[j])) {
isAns[i] = false;
break;
}
}
bool flag = false;
printf("Top sticks:");
for(int i = ; i < n; ++i) {
if(!isAns[i]) continue;
if(flag) printf(",");
else flag = true;
printf(" %d", i + );
}
puts(".");
}
}

POJ 2653 Pick-up sticks(线段判交)的更多相关文章

  1. (线段判交的一些注意。。。)nyoj 1016-德莱联盟

    1016-德莱联盟 内存限制:64MB 时间限制:1000ms 特判: No通过数:9 提交数:9 难度:1 题目描述: 欢迎来到德莱联盟.... 德莱文... 德莱文在逃跑,卡兹克在追.... 我们 ...

  2. (叉积,线段判交)HDU1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

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

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

  4. POJ 1556 The Doors 线段判交+Dijkstra

    The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6734   Accepted: 2670 Descrip ...

  5. (计算几何 线段判交) 51nod1264 线段相交

    1264 线段相交 给出平面上两条线段的两个端点,判断这两条线段是否相交(有一个公共点或有部分重合认为相交). 如果相交,输出"Yes",否则输出"No".   ...

  6. 线段相交 POJ 2653

    // 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...

  7. poj 2653 线段与线段相交

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11884   Accepted: 4499 D ...

  8. POJ 2653

    题目大意:一个小孩不断往地上扔棍子,共n根,求结束后共有多少根不与去他相交. 解法思路:典型的判断线段相交问题,利用快速排斥+双跨立判断相交,最后输出没相交的. (图片来源:http://www.2c ...

  9. The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

随机推荐

  1. 技巧:Vimdiff 使用(改)

    技巧:Vimdiff 使用(改) 各种 IDE 大行其道的同时,传统的命令行工具以其短小精悍,随手可得的特点仍有很大的生存空间,这篇短文介绍了一个文本比较和合并的小工具:vimdiff.希望能对在 U ...

  2. ABAP术语-SAPNET

    SAPNET 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/17/1109823.html SAPNet is the intranet p ...

  3. VirtualBox复制的虚拟机无法获取IP解决办法

    自从建立了这个账号后写了一篇,好几年没来了,今天来看看,顺便分享一下. 昨天晚上想玩玩zookeeper集群,在vb里复制了一台主机,可怎么也无法获取IP,经研究,终于还是解决了. 1.复制主机时勾选 ...

  4. swift3.0 保存图片到本地,申请权限

    1.info中写上 <key>NSCameraUsageDescription</key> <string>需要您的同意才能读取媒体资料库</string&g ...

  5. 获取当前对象的key的名称

    获取当前对象的key的名称(无法获取),只能曲线救国 通过给标签添加class,id, 然后通过对class的遍历,来获取到id(这个id对应数据库的字段,所以对应对象的key) 然后再给 id 赋值 ...

  6. SQL语言简单总结

    常用的Sql语言总结: 1. create datebase  datebaseName         //创建数据库 2. drop datebase  datebaseName    //    ...

  7. MySQL至TiDB复制延迟监控

    因生产环境mysql中有较多复杂sql且运行效率低,因此采用tidb作为生产环境的从库进行部分慢sql及报表的读写分离.其中MySQL至TIDB采用Syncer工具同步.关于TIDB的安装及Synce ...

  8. go学习笔记-错误处理

    错误处理 通过内置的错误接口提供了非常简单的错误处理机制. error类型是一个接口类型 type error interface { Error() string } 可以在编码中通过实现 erro ...

  9. HyperLedger Fabric 1.4 多机多节点部署(10.3)

    多机多节点指在多台电脑上部署多个组织和节点,本案例部署一个排序(orderer)服务,两个组织(org1,org2)和四个节点(peer),每个组织包括两个节点,需要五台计算机,计算机配置如下: 多机 ...

  10. Go语言中的流程控制

    1 概述 Go语言提供了条件分支 if,状态分支 switch,循环 for,跳转 goto,延迟执行 defer,这些流程控制语句.分别作说明如下: 2 条件分支 if 依据条件是否满足确定执行哪个 ...