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. PotPlayer 禁止更新

      PotPlayer设置禁止更新 CreateTime--2016年10月15日22:37:49 迁移时间:2017年8月9日15:36:48 Author:Marydon UpdateTime-- ...

  2. 【微信开发】JS和PHP分别判断当前浏览器是否微信浏览器

    1.PHP端 //判断是否微信浏览器 -xzz1125 function is_weixin() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMes ...

  3. 乱码字符引起的JSON转换失败

        这种问题有两个解决办法,使用后不管你是什么特殊字符还是什么西欧字体还是什么稀奇古怪的内容都可以完美解决!   1.要把即将转换为json的内容先转换为unicode编码,json转换无误后,使 ...

  4. js判断浏览器是否关闭

    http://www.blogjava.net/wyz191/archive/2008/12/08/245089.html JS   window.onunload=function(){      ...

  5. c#中用DirectShow实现媒体播放器

    原文地址:https://www.cnblogs.com/aiqingqing/p/4338448.html 用.net做多媒体开发的似乎不多,所以网上资源也少,看的人更少.不过我的博客上居然还有几位 ...

  6. log4cplus基础知识

    一.简介: log4cplus是C++编写的开源的日志系统. 具有线程安全.灵活.以及多粒度控制的特点,通过将信息划分优先级使其可以面向程序调试.运行.测试.和维护等全生命周期: 你可以选择将信息输出 ...

  7. SDK Manager 闪退的解决方式

    打开电脑的执行  也就是win+R键    然后在命令行里面打上android即可了

  8. bcdedit

    我的电脑装了双系统:Win2003 SP2(C盘)和Win2008 SP2(D盘),最近2003一启动就蓝屏unknown hard error,安全模式也进不去,恢复注册表等方法试过也不行,但200 ...

  9. Java 枚举(enum) 的常见用法和开发规范

    JDK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 用法一:常量 在JDK1.5 之前,我们定义常量都是: public static final ...

  10. 04、Quick Start for Windows

    创建一个新工程 1.在 VS 上,选择 File > New > Project.. 2.在新工程窗口,选择  Visual C# > Windows Store > Blan ...