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 ...
随机推荐
- Android 系统服务一览表
在<Zygote进程[3]--SystemServer的诞生>一文中介绍了SystemServer的诞生,本文来看一下SystemServer中初始化的系统服务. 1.AccountMan ...
- 关于SpringCloud微服务架构概念的一点理解
目前微服务是非常火的架构或者说概念,也是在构建大型互联网项目时采用的架构方式. 1.单体架构单体架构,是指将开发好的项目打成war包,然后发布到tomcat等容器中的应用. 假设你正准备开发一款与Ub ...
- 500 OOPS: vsftpd: cannot locate user specified in 'chown_username':whoever
错误:500 OOPS: vsftpd: cannot locate user specified in 'chown_username':whoever解决方案:在vsftpd.conf中修改如下两 ...
- 网站日志访问记录组件UserVisitLogsHelp开源了!
之前在<一种基于自定义代码记录用户访问日志在Sharepoint网站的应用方法!>一文利用本人几年前的开发的UserVisitLogsHelp组件进行了网站用户访问日志记录,可用于网站分析 ...
- C#一个FTP操作封装类FTPHelper
参考了网上一些代码,作了一些调整优化. 001 using System; 002 using System.Collections.Generic; 003 using System.Linq; 0 ...
- 高人对libsvm的经典总结(全面至极)
==>转自:http://blog.163.com/crazyzcs@126/blog/static/129742050201061192243911/ http://www.ilovematl ...
- wstring to wchar_t*
If you want to convert from std::wstring to const WCHAR* (i.e. the returned pointer gives read-onl ...
- 算法(第四版)学习笔记之java实现希尔排序
希尔排序思想:使数组中随意间隔为h的元素都是有序的. 希尔排序是插入排序的优化.先对数组局部进行排序,最后再使用插入排序将部分有序的数组排序. 代码例如以下: /** * * @author seab ...
- nginx+tomcat+redis完成session共享(转载)
转载:http://blog.csdn.net/grhlove123/article/details/48047735 tomcat7下基于redis的session共享所需jar包: http:// ...
- IE 之 应用小结
1. 导出收藏夹(IE11) 导出:打开浏览器, 文件(F) → 导入和导出(M)... → 导出到文件(E) → 指定导出内容 → 指定保存路径导入:打开浏览器,文件(F) → 导入和导出(M).. ...