POJ2653
来源:互联网 发布:苹果茶软件 编辑:程序博客网 时间:2024/05/19 19:40
唔,这也是一道水题。判断线段相交~~~开始TLE那是在循环里面没有加break;加上就AC了~~~
上代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
struct point{
double x;
double y;
};
struct point a[100010][2];
int b[100010];
int dblcmp(double d){
if(fabs(d)<1e-6)
return 0;
else{
if(d>0)
return 1;
else
return -1;
}
}
double det(double x1,double y1,double x2,double y2){
return x1*y2-x2*y1;
}
double cross(struct point a,struct point b,struct point c){
return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
int segcrossSimple(struct point a,struct point b,struct point c,struct point d){
return dblcmp(cross(a,c,d))*dblcmp(cross(b,c,d))+dblcmp(cross(c,a,b))*dblcmp(cross(d,a,b));
}
main(){
int n,i,j;
while(scanf("%d",&n)!=-1 && n!=0){
memset(b,0,sizeof(b));
for(i=0;i<=n-1;i++){
scanf("%lf %lf %lf %lf",&a[i][0].x,&a[i][0].y,&a[i][1].x,&a[i][1].y);
}
for(i=0;i<=n-2;i++){
for(j=i+1;j<=n-1;j++){
if(segcrossSimple(a[i][0],a[i][1],a[j][0],a[j][1])<0){
b[i]=1;
break;
}
}
}
printf("Top sticks:");
for(i=0;i<=n-2;i++)
if(b[i]==0)
printf(" %d,",i+1);
printf(" %d.\n",n);
}
}
- poj2653
- POJ2653
- POJ2653
- poj2653
- poj2653
- Poj2653
- poj2653
- poj2653解题报告
- poj2653 - Pick-up sticks
- 线段相交 poj2653
- POJ2653 Pick-up sticks
- POJ2653-Pick-up sticks
- poj2653-Pick-up sticks
- poj2653 Pick-up sticks
- POJ2653->判断线段相交
- poj2653 Pick-up sticks
- poj2653 Pick-up sticks
- poj2653 线段相交的判断
- poj 1276Cash Machine
- 基本功能。比较字符串。读写字符串 转载
- 最新MyEclipse下hibernate开发环境的配置(hibernate+annotation+log4j )
- mysql 联合查询中and or的使用
- spring2.5 注入 构造器
- POJ2653
- MYSQL联合查询中GROUP_CONCAT、MAX、year使用
- ChartDirector破解
- 存储数组之serialize与unserialize
- MVVM中轻松控制ProgressBar
- 幸福是一种明白
- 基于B/S+C/S模式的期刊网络采编系统研究及其应用
- silverlight文件下载方法
- sqlserver学习心得