Pick-up sticks

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1872    Accepted Submission(s): 706

Problem 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.
 
Source
 
Recommend
Eddy   |   We have carefully selected several similar problems for you:  1142 1392 1148 1145 1155 

 
  计算几何,判断两线段相交
  题意是依次放置线段,相交即摞在上面,求最后在最上面的线段。
  急躁了,思路彻底乱了,最后还是参考了别人的代码。比赛的时候如果是这种状态,那绝对会拖累队友。
 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; struct Point{
double x,y;
};
struct Line{
Point p1,p2;
}l[];
double Max(double a,double b)
{
return a>b?a:b;
}
int MaxInt(int a,int b)
{
return a>b?a:b;
}
double Min(double a,double b)
{
return a<b?a:b;
}
double xmulti(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
bool inter(Line l1,Line l2)
{
if( Min(l2.p1.x,l2.p2.x)<=Max(l1.p1.x,l1.p2.x) &&
Min(l2.p1.y,l2.p2.y)<=Max(l1.p1.y,l1.p2.y) &&
Min(l1.p1.x,l1.p2.x)<=Max(l2.p1.x,l2.p2.x) &&
Min(l1.p1.y,l1.p2.y)<=Max(l2.p1.y,l2.p2.y) &&
xmulti(l1.p1,l2.p2,l2.p1)*xmulti(l1.p2,l2.p2,l2.p1)< &&
xmulti(l2.p1,l1.p2,l1.p1)*xmulti(l2.p2,l1.p2,l1.p1)< )
return true;
else
return false;
}
bool isv[];
int main()
{
int n;
while(cin>>n){
if(n==) break;
memset(isv,,sizeof(isv));
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&l[i].p1.x,&l[i].p1.y,&l[i].p2.x,&l[i].p2.y);
}
int num = n;
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
if(inter(l[i],l[j])){
isv[i] = ;
num--;
break;
} printf("Top sticks: ");
//输出所有存在的线段(即最顶上的线段)
for(int i=;i<=n;i++)
if(!isv[i]){ //是顶
num--;
if(num==)
printf("%d.\n",i);
else
printf("%d, ",i);
}
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 1147:Pick-up sticks(基本题,判断两线段相交)的更多相关文章

  1. poj 1127:Jack Straws(判断两线段相交 + 并查集)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2911   Accepted: 1322 Descr ...

  2. hdu 1086: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. You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交

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

  4. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  5. HDU 1147 /// 判断两线段相交

    题目大意: 给定n条线段的端点 依次放上n条线段 判断最后在最上面(不被覆盖)的线段有哪些 到当前线段后 直接与之前保存的未被覆盖的线段判断是否相交就可以了 #include <cstdio&g ...

  6. TOJ1840: Jack Straws 判断两线段相交+并查集

    1840: Jack Straws  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Submit: 1 ...

  7. hdu 1086 You can Solve a Geometry Problem too [线段相交]

    题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...

  8. ACM1558两线段相交判断和并查集

    Segment set Problem Description A segment and all segments which are connected with it compose a seg ...

  9. 简单地判断判断两矩形相交/重叠 C#

    最近需要用到矩形相交算法的简单应用,所以特地拿一个很简单的算法出来供新手参考,为什么说是给新手的参考呢因为这个算法效率并不是很高,但是这个算法只有简简单单的三行.程序使用了两种方法来判断是否重叠/相交 ...

随机推荐

  1. Commons FileUpLoad 两种上传方式解

    traditional API (传统方式) //上传路径 File file = new File("C:/upload"); //临时文件路径 File tempFile = ...

  2. ServletConfig讲解

    1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些初始化参数. 例如: <ser ...

  3. 如何发布本地maven项目jar包部署到nexus私服?

    首先在我们的pom里面描述我们要部署的地址: <distributionManagement> <repository> <id>release</id> ...

  4. 深层神经网络框架的python实现

    概述 本文demo非常适合入门AI与深度学习的同学,从最基础的知识讲起,只要有一点点的高等数学.统计学.矩阵的相关知识,相信大家完全可以看明白.程序的编写不借助任何第三方的深度学习库,从最底层写起. ...

  5. Linux环境源码编译安装SVN

    zhoulf 2015/2/28 原创 安装说明 安装环境:Red Hat Enterprise Linux 安装方式:源码安装 软件:apr-1.5.0.tar.gz.apr-iconv-1.2.1 ...

  6. opensips编译安装时可能遇到的问题

    错误一: ERROR: could not load the script in /usr/local//lib64/opensips/opensipsctl/opensipsdbctl.pgsql ...

  7. PostgreSQL在线安装

    背景:CentOS 7 一.在线yum安装 yum -y install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7 ...

  8. C# BackgroundWorker的Bug???

    废话不多说,上代码: public partial class Form1 : Form { BackgroundWorker _bgWorker; int count; public Form1() ...

  9. django Proxy models ---- 代理模式

    一个proxy models 不会在数据库中创建新的表.而是与它的基类共用同一个表 1.model 的定义: from django.db import models # Create your mo ...

  10. 二级指针 (C语言)

    二级指针又叫双指针.C语言中不存在引用,所以当你试图改变一个指针的值的时候必须使用二级指针.C++中可以使用引用类型来实现. 下面讲解C中的二级指针的使用方法. 例如我们使用指针来交换两个整型变量的值 ...