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

Problem Description
Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare a geometry problem for this final exam. According to the experience of many ACMers, geometry problems are always much trouble, but this problem is very easy, after all we are now attending an exam, not a contest :)
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.

 
Input
Input contains multiple test cases. Each test case contains a integer N (1=N<=100) in a line first, and then N lines follow. Each line describes one segment with four float values x1, y1, x2, y2 which are coordinates of the segment’s ending.
A test case starting with 0 terminates the input and this test case is not to be processed.
 
Output
For each case, print the number of intersections, and one line one case.
 
Sample Input
2 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.00 3 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.000 0.00 0.00 1.00 0.00 0
 
Sample Output
1 3
 
Author
lcy
 线段是否相交的判断,采用的石墨板,..
代码:
  1. #include<stdio.h>
  2. #include<math.h>
  3. const double eps=1e- ;
  4. typedef struct
  5. {
  6. double x,y;
  7. }point;
  8.  
  9. double min(double a, double b)
  10. {
  11. return a<b?a:b;
  12. }
  13. double max(double a,double b)
  14. {
  15. return a>b?a:b;
  16. }
  17. //判断线段是否有焦点
  18. bool inter(point a ,point b, point c ,point d)
  19. {
  20. if(min(a.x,b.x)>max(c.x,d.x)||min(a.y,b.y)>max(c.y,d.y)||
  21. min(c.x,d.x)>max(a.x,b.x)||min(c.y,d.y)>max(a.y,b.y))
  22. return ;
  23. double h,i,j,k;
  24. h=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
  25. i=(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x);
  26. j=(d.x-c.x)*(a.y-c.y)-(d.y-c.y)*(a.x-c.x);
  27. k=(d.x-c.x)*(b.y-c.y)-(d.y-c.y)*(b.x-c.x);
  28. return h*i<=eps&&j*k<=eps;
  29. };
  30. point st[],en[];
  31. int main()
  32. {
  33. int n,j,i,cnt=;
  34. while(scanf("%d",&n),n)
  35. {
  36. cnt=;
  37. for( i= ; i<n ; i++ )
  38. scanf("%lf%lf%lf%lf",&st[i].x,&st[i].y,&en[i].x,&en[i].y);
  39.  
  40. for( i= ; i<n ; i++ )
  41. {
  42. for(j=i+ ; j<n ;j++ )
  43. {
  44. if(inter(st[i],en[i],st[j],en[j]))
  45. cnt++;
  46. }
  47. }
  48. printf("%d\n",cnt);
  49. }
  50. return ;
  51. }
 

HDUOJ1086You can Solve a Geometry Problem too的更多相关文章

  1. 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 ...

  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. (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/ ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. (叉积,线段判交)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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. linux统计文件夹内文件数

    for dir in `find ./ -type d ` ;do echo -n "$dir "  ;find $dir  -type f | wc -l ;echo " ...

  2. 局域网Cesium离线影像及瓦片影像地图加载【转】

    http://www.mamicode.com/info-detail-2161992.html 1.Cesium简介 优点: cesium展示地图数据效果比较好,解析2D地图各种不同服务类型的数据源 ...

  3. iOS开发-UIApplication和App启动状态

    UIApplication简单从字面上了解就是应用程序,开发的时候有的时候会根据需要调用其中的方法,看起来不起眼,实际在iOS开发UIApplication提供了iOS程序运行期间的控制和协作工作.每 ...

  4. Volley框架的介绍使用

    Volley是在2013年的Google I/O 2013大会上发布的,是我们的网络通信更快,更简单,更方便.对于初学者来讲是一个很好的框架. 简单来说,它提供了如下的便利功能: JSON,图像等的异 ...

  5. Android -- 程序启动画面 Splash

    很多应用都会有一个启动界面.欢迎画面慢慢隐现,然后慢慢消隐. 我的方式是使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一 ...

  6. 【5】基于Log4Net的日志系统

    阅读目录 日志系统应具备的特性  Log4Net 配置文件:log4net.config 初始化 输出信息 对Log4Net的封装 log4net.config复杂配置   不管是Web应用程序还是W ...

  7. 你使用 Web 平台安装程序命令行工具

    你使用 Web 平台安装程序命令行工具 获取的软件由其所有者授权给你.Microsoft 未授予你第三方软件的任何权利.已成功加载主源: https://go.microsoft.com/?linki ...

  8. 一款纯css实现的垂直时间线效果

    今天给大家分享一款纯css实现的垂直时间线效果.垂直时间线适合放在类似任务时间安排的网页上.该实现采用了蓝色作为主题色,界面效果还不错.一起看下效果图: 实现的代码. html代码: ... 阅读原文 ...

  9. C#.NET常见问题(FAQ)-浮点数如何四舍五入

    使用Math.Round方法即可实现保留指定的小数点后面位数,这种方法返回的还是double类型,而ToString方法并没有做实际转换   更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: ...

  10. 高可用性(HA) 4 - network bonding

    我们都知道,hadoop namenode是一个臭名昭著的单点故障点(SPOF). 当你找到一篇High  Availability的文章, 以为使用heartbeat/pacemaker, coro ...