poj 2653 (线段相交判断)
http://poj.org/problem?id=2653
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 9531 | Accepted: 3517 |
Description
Input
Output
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm> using namespace std;
#define MAXX 100010
#define eps 1e-6 typedef struct point
{
double x,y;
}point; typedef struct
{
point st,ed;
}line; bool xy(double x,double y){ return x<y-eps; }
bool dy(double x,double y){ return x>y+eps; }
bool xyd(double x,double y){ return x<y+eps; }
bool dyd(double x,double y){ return x>y-eps; }
bool dd(double x,double y){ return fabs(x-y)<eps; } double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} bool onSegment(point a,point b,point c)
{
double maxx=max(a.x,b.x);
double maxy=max(a.y,b.y);
double minx=min(a.x,b.x);
double miny=min(a.y,b.y);
if(dd(crossProduct(a,b,c),0.0)&&dyd(c.x,minx)
&&xyd(c.x,maxx)&&dyd(c.y,miny)&&xyd(c.y,maxy))
return true;
return false;
} bool segIntersect(point p1,point p2,point p3,point p4)
{
double d1=crossProduct(p3,p4,p1);
double d2=crossProduct(p3,p4,p2);
double d3=crossProduct(p1,p2,p3);
double d4=crossProduct(p1,p2,p4);
if(xy(d1*d2,0.0)&&xy(d3*d4,0.0))
return true;
if(dd(d1,0.0)&&onSegment(p3,p4,p1))
return true;
if(dd(d2,0.0)&&onSegment(p3,p4,p2))
return true;
if(dd(d3,0.0)&&onSegment(p1,p2,p3))
return true;
if(dd(d4,0.0)&&onSegment(p1,p2,p4))
return true;
return false;
} point p[MAXX];
line li[MAXX];
int num[MAXX]; int main()
{
int m,n,i,j;
while(scanf("%d",&n)!=EOF&&n)
{
memset(num,,sizeof(num));
for(i=;i<n;i++)
{
scanf("%lf%lf%lf%lf",&li[i].st.x,&li[i].st.y,&li[i].ed.x,&li[i].ed.y);
}
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
{
if(segIntersect(li[i].st,li[i].ed,li[j].st,li[j].ed))
{
num[i]++;
break;
} }
}
int cas=,tes=,tmp;
//int str[MAXX];
for(i=;i<n;i++)
{
if(num[i] == )
{
cas++;
}
}
printf("Top sticks: ");
for(i=;i<n;i++)
{
if(num[i] == && tes<cas-)
{
printf("%d, ",i+);
tes++;
tmp=i;
}
}//printf("%d**",i);
for(j=tmp+;j<n;j++)
{
if(num[j] == )
{
printf("%d.\n",j+);
}
}
}
return ;
}
poj 2653 (线段相交判断)的更多相关文章
- poj 2653 线段相交
题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...
- poj 2653 线段相交裸题(解题报告)
#include<stdio.h> #include<math.h> const double eps=1e-8; int n; int cmp(double x) { if( ...
- poj 1410 线段相交判断
http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Pick-up sticks - POJ 2653 (线段相交)
题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍..... 分析:可以维护一个队列,如果木棍没有被压着就入队列,如果判断被压着,就让那个压着的出队列,最后把这个木棍放进队列, ...
- poj 2653 线段与线段相交
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11884 Accepted: 4499 D ...
- POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1243 Accepted: 524 D ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- poj 1269 线段相交/平行
模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...
随机推荐
- lamp环境编译错误
GD 编译出错解决方法 编译最新的2.0.35版本,用默认的 ./configure编译 当make的时候,出现以下错误 configure.ac:64: error: possibly undefi ...
- uboot启动参数
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0bootdelay=2baudrate=115200ethaddr=08:00:3 ...
- nohup DEMO
nohup,顾名思义:挂起免疫. nohup命令可以防止当你退出系统时,在后台运行的进程被终止.它能让你运行的命令或脚本在你退出系统后继续在后台运行. nohup命令不能自动的将任务放在后台运行,所以 ...
- 为Docker容器配置固定IP
当docker以桥接的方式启动容器时,容器内部的IP是经过DHCP获取的,例如:172.17.0.8/32,且每重启依次IP都会发生变动.某些特殊的情况下,需要容器内有自己固定的一个内部IP.我的实现 ...
- textarea 在浏览器中禁用拖动和固定大小
HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...
- HDU 1827:Summer Holiday(强连通)
http://acm.hdu.edu.cn/showproblem.php?pid=1827 思路:强连通分量缩点后找入度为0的点,然后对于属于该强连通分量的找一个最小耗费的入口. #include ...
- c# web 缓存管理
using System; using System.Collections; using System.Text.RegularExpressions; using System.Web; usin ...
- js笔记----(运动)分享 隐藏/显示
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- SlickGrid example 3a: 可编辑单元
可编辑单元支持一列展示多个属性域,可以为编辑单元提供验证,并且自定义验证事件. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 T ...
- 实现Fragment的切换和ViewPager自动循环设置切换时间
1.FragmentActivity与Fragment之间的用法 2.实现ViewPager自动轮换,设置移动的时间 通过反射获取mScrooler这个对象: Field mScroller; mSc ...