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. bzoj4552: [Tjoi2016&Heoi2016]排序(二分+线段树)

    又是久违的1A哇... 好喵喵的题!二分a[p],把大于mid的数改为1,小于等于mid的数改为0,变成01串后就可以用线段树进行那一连串排序了,排序后如果p的位置上的数为0,说明答案比mid小,如果 ...

  2. taotao服务测试http请求需要返回json时出现406错误处理

    @Test public void doPost() throws Exception { CloseableHttpClient httpClient = HttpClients.createDef ...

  3. sql中按in中的ID进行排序输出

    builder.OrderBy("charindex(','+convert(varchar,ID)+',',',"+chufenOrder+"') ");

  4. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  5. Wand FZU - 2282 全错位重排

    N wizards are attending a meeting. Everyone has his own magic wand. N magic wands was put in a line, ...

  6. Debug模式下加载文件,运行程序异常的慢

    今天在进行单元测试的时候,debug模式下加载速度很慢,但是run模式下速度很快. 原因:在debug模式下,断点位置不当,解决办法 移除编译器中的所有断点.

  7. js对数组的常用操作

    在js中对数组的操作是经常遇到的,我呢在这就列一下经常用到的方法 删除数组中的元素: 1.delete方法:delete删除的只是数组元素的值,所占的空间是并没有删除的 代码: var arr=[12 ...

  8. HUST 1103 校赛 邻接表-拓扑排序

    Description N students were invited to attend a party, every student has some friends, only if someo ...

  9. CentOS7 搭建Apache环境

    一.安装 yum -y install httpd 二.配置 主路径:/etc/httpd/ Apache目录说明 1 2 3 4 5 6 drwxr-xr-x 2 root root 4096 Ma ...

  10. python大数据挖掘系列之淘宝商城数据预处理实战

    数据清洗: 所谓的数据清洗,就是把一些异常的.缺失的数据处理掉,处理掉不一定是说删除,而是说通过某些方法将这个值补充上去,数据清洗目的在于为了让我们数据的可靠,因为脏数据会对数据分析产生影响.拿到数据 ...