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. 【bzoj2743】[HEOI2012]采花 树状数组

    题目描述 萧芸斓是Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便于公 ...

  2. 征战jQuery

    一:jQuery的用途 1>.访问 和 操作 DOM元素 2>.控制 页面样式 3>.对页面事件的处理 4>.方便的使用jQuery插件 5>.与Ajax技术的完美结合 ...

  3. bzoj1706: [Usaco2007 Nov]relays 奶牛接力跑 (Floyd+新姿势)

    题目大意:有t(t<=100)条无向边连接两点,求s到e刚好经过n(n<=10^7)条路径的最小距离. 第一反应分层图,但是一看n就懵逼了,不会写.看了题解之后才知道可以这么玩... 首先 ...

  4. LAMP架构的搭建 和wordpress

    [root@yu ~]#   yum install httpd php php-mysql mysql-server mysql -y 安装php [root@yu ~]# service http ...

  5. 中国MOOC_面向对象程序设计——Java语言_第1周 类与对象

    第1周编程题 查看帮助 返回   我们在题目说明中给出了一部分代码,你需要在这部分代码的基础上,按照题目说明编写代码,然后将两部分代码一起提交. 依照学术诚信条款,我保证此作业是本人独立完成的. 温馨 ...

  6. ubuntu 服务器搭建汇总

    开启ssh 1.首先:终端安装开启ssh-server服务: sudo apt-get install openssh-server 2.然后确认sshserver是否启动了: ps-e | grep ...

  7. 打开cmd窗口新技巧get

    1.在当前目录下,按住shift键+点击右键,选择在此处打开命令窗口 很多时候我们需要打开命令行然后进入到相应目录进行一些操作. 常规的做法是: Win+R打开运行窗口 输入"cmd&quo ...

  8. mybatis 热部署xml文件(spring boot和springmvc两种方式)

    参考:http://thinkgem.iteye.com/blog/2304557 步骤:1.创建两个java类 (1)MapperRefresh.java   :用于刷新mapper (2)SqlS ...

  9. Git新手上路,让你快速掌握Git的基本使用

    github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开.这对于一般人来说公共仓库就已经足够了. 1.注册账户以及创建仓库     要想 ...

  10. 【BZOJ4880】排名的战争 [暴力]

    排名的战争 Time Limit: 8 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 小Q是一名出色的质检员,他负责质检 ...