Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 10364   Accepted: 3842

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.

Source

/**
题意:给出n条线段,然后取没有被覆盖的;
做法:计算几何(线段相交)
**/
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#define maxn 100000+ 10
using namespace std;
int n,m;
int mmap[maxn];
const double eps = 1e-;
const double PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps) return ;
if(x < ) return -;
return ;
}
struct Point
{
double x;
double y;
Point() {}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator - (const Point &b) const
{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b) const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b) const
{
return x*b.x + y*b.y;
}
} point[maxn];
struct Line
{
Point s;
Point e;
Line() {}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
} line[maxn];
bool inter(Line l1,Line l2)
{
return max(l1.s.x ,l1.e.x) >= min(l2.s.x,l2.e.x) &&
max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
sgn((l2.s - l1.e) ^(l1.s-l1.e) )*sgn((l2.e - l1.e)^(l1.s-l1.e) )<= &&
sgn((l1.s - l2.e) ^(l2.s- l2.e)) *sgn((l1.e - l2.e) ^(l2.s - l2.e)) <=;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int n;
while(~scanf("%d",&n))
{
if(n == ) break;
double a,b,c,d;
for(int i=; i<n; i++)
{
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
line[i] = Line(Point(a,b),Point(c,d));
}
memset(mmap,,sizeof(mmap));
for(int i=; i<n; i++)
{
for(int j=i+; j<n; j++)
{
if(inter(line[i],line[j]))
{
mmap[i] = ;
break;
}
}
}
printf("Top sticks: ");
int res = ;
for(int i=; i<n; i++)
{
if(mmap[i] == )
{
if(res != ) printf(", ");
printf("%d",i+);
res++;
}
}
printf(".\n");
}
return ;
}

POJ-2563的更多相关文章

  1. POJ 1390 Blocks(记忆化搜索+dp)

    POJ 1390 Blocks 砌块 时限:5000 MS   内存限制:65536K 提交材料共计: 6204   接受: 2563 描述 你们中的一些人可能玩过一个叫做“积木”的游戏.一行有n个块 ...

  2. poj和hdu部分基础算法分类及难度排序

    最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  5. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  6. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  7. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  8. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  9. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  10. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

随机推荐

  1. React Patterns

    Contents Stateless function JSX spread attributes Destructuring arguments Conditional rendering Chil ...

  2. 【DP】【P1586】四方定理

    传送门 Description Input 第一行为一个整数T代表数据组数,之后T行每行一个数n代表要被分解的数 Output 对于每个n输出一行,为方案个数 Sample Input Sample ...

  3. MongoDB插入数据的3种方法

    insert()方法: 下面是在inventory集合中插入一个三个字段的文档: db.inventory.insert( { _id: 10, type: "misc", ite ...

  4. 树莓派搭建LAMP,然后更改根目录

    参考网页: http://shumeipai.nxez.com/2013/10/13/install-and-config-lamp.html http://blog.csdn.net/zzuzadz ...

  5. Kafka消息delivery可靠性保证(Message Delivery Semantics)

    原文见:http://kafka.apache.org/documentation.html#semantics kafka在生产者和消费者之间的传输是如何保证的,我们可以知道有这么几种可能提供的de ...

  6. CMDB资产管理系统开发【day26】:CMDB上节回顾

    一.上节知识点回顾 服务器设计了一个表结构 开发了一个客户端 二.后台创建缓存区表 客户端连接服务器,在服务器的下面看报错信息 因为URL都没有写,所以我找不到呀 1.在MadKing\url.py ...

  7. ES6数组的扩展运算符

    一.基本使用 ES6中函数可以使用 rest参数 接收函数的多余参数,组成一个数组,放在形参的最后面. let fn = (a, ...value) => { console.log(a); c ...

  8. DBA操作常用命令

    一.ORACLE的启动和关闭   1.在单机环境下   要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下   su - oracle      a.启动ORACLE系统   orac ...

  9. HDU 5950Recursive sequence ICPC沈阳站

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  10. HDU 5901 Count primes 大素数计数

    题意:计算1~N间素数的个数(N<=1e11) 题解:题目要求很简单,作为论文题,模板有两种 \(O(n^\frac{3}{4} )\),另一种lehmer\(O(n^\frac{2}{3})\ ...