HDUOJ1086You can Solve a Geometry Problem too
You can Solve a Geometry Problem too
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6340 Accepted Submission(s): 3064
Give you N (1<=N<=100) segments(线段), please output the number of all intersections(交点). You should count repeatedly if M (M>2) segments intersect at the same point.
Note:
You can assume that two segments would not intersect at more than one point.
A test case starting with 0 terminates the input and this test case is not to be processed.
#include<stdio.h>
#include<math.h>
const double eps=1e- ;
typedef struct
{
double x,y;
}point; double min(double a, double b)
{
return a<b?a:b;
}
double max(double a,double b)
{
return a>b?a:b;
}
//判断线段是否有焦点
bool inter(point a ,point b, point c ,point d)
{
if(min(a.x,b.x)>max(c.x,d.x)||min(a.y,b.y)>max(c.y,d.y)||
min(c.x,d.x)>max(a.x,b.x)||min(c.y,d.y)>max(a.y,b.y))
return ;
double h,i,j,k;
h=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
i=(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x);
j=(d.x-c.x)*(a.y-c.y)-(d.y-c.y)*(a.x-c.x);
k=(d.x-c.x)*(b.y-c.y)-(d.y-c.y)*(b.x-c.x);
return h*i<=eps&&j*k<=eps;
};
point st[],en[];
int main()
{
int n,j,i,cnt=;
while(scanf("%d",&n),n)
{
cnt=;
for( i= ; i<n ; i++ )
scanf("%lf%lf%lf%lf",&st[i].x,&st[i].y,&en[i].x,&en[i].y); for( i= ; i<n ; i++ )
{
for(j=i+ ; j<n ;j++ )
{
if(inter(st[i],en[i],st[j],en[j]))
cnt++;
}
}
printf("%d\n",cnt);
}
return ;
}
HDUOJ1086You can Solve a Geometry Problem too的更多相关文章
- HDU1086You can Solve a Geometry Problem too(判断线段相交)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- 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 ...
- (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)
称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- HDU 1086:You can Solve a Geometry Problem too
pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 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 ...
- You can Solve a Geometry Problem too(线段求交)
http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2000 ...
- (叉积,线段判交)HDU1086 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 ...
- 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 ...
- 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 ...
随机推荐
- matlab 投影
function[l]= Gray(I) % I: The name of image A=imread(I);m=0;n=0;[m,n]= size(A);Hproj=zeros(m,1);Vpro ...
- C预编译, 预处理, C/C++头文件, 编译控制,
在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的 ...
- VS2010+OpenCV2.4.3配置
VS2010+OpenCV2.4.3配置: 环境变量path: D:\openCV2.4.3\opencv\build\x86\vc10\bin 项目-属性-VC++目录:(vs2008中,工具- ...
- 线程池的corePoolSize、maximumPoolSize和poolSize
什么是线程池: 为了避免系统频繁的创建和销毁线程,我们可以将创建的线程进行复用.在线程池中总有那么几个活跃的线程,也有一定的最大值限制,一个业务使用完线程之后,不是立即销毁而是将其放入到线程池中,从而 ...
- mybatis映射文件遇到的小问题
mybatis的映射文件插入操作时: 如果对应的属性是String类型的,那么一定要做空串的判断. 比如注册的时候,如果需要向数据库中插入一条记录时,对应的字段没有给他赋值,这个String类型的值传 ...
- 3D屏保程序:汉诺塔
学过程序的人一定记得汉诺塔.我们学的第一个程序是HelloWorld,而碰到的第一个坑就是汉诺塔,短短十几行代码,不知花费了多少时间精力去理解.我记得当年的开发环境还是蓝屏的,汉诺塔程序的输出还是一行 ...
- vue-router路由知识补充
1.render函数 var app = new Vue({ el: '#app', router, render: h => h(App) //新添加的函数操作 }) 我们新加了render: ...
- ps aux命令解析
auxa 显示所有与终端相关的进程,由终端发起的.x 显示所有与终端无关的进程.u 显示用户导向的用户列表.VSZ 虚拟内存集,进程占用的虚拟内存空间RSS 物理内存集,进程战用实际物理内存空间.S ...
- 空格在Html中的表示方法( 含义)
转自:http://www.cnblogs.com/hailexuexi/archive/2010/07/25/1784611.html 在web开发经常会遇到如: 这样的字符.它其实是Html将 ...
- Office WORD如何关闭自动检查语法
只要把打钩的地方全部去掉即可.