HDU 1086 You can Solve a Geometry Problem too
来源:互联网 发布:计算机mac地址是什么 编辑:程序博客网 时间:2024/06/12 00:02
You can Solve a Geometry Problem too
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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.
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.
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
20.00 0.00 1.00 1.000.00 1.00 1.00 0.0030.00 0.00 1.00 1.000.00 1.00 1.00 0.0000.00 0.00 1.00 0.000
Sample Output
13
题意:给你n条线段,判断它们有多少个交点,交点需要重复计算。
注意向量的点乘与叉乘
#include<stdio.h>struct xian{ double x1,y1; double x2,y2;}f[101];bool find(xian a,xian b){if(((a.x1-b.x1)*(a.y2-b.y1)-(a.x2-b.x1)*(a.y1-b.y1))*((a.x1-b.x2)*(a.y2-b.y2)-(a.x2-b.x2)*(a.y1-b.y2))>0)return false;if(((b.x1-a.x1)*(b.y2-a.y1)-(b.x2-a.x1)*(b.y1-a.y1))*((b.x1-a.x2)*(b.y2-a.y2)-(b.x2-a.x2)*(b.y1-a.y2))>0)return false;return true;}int main(){ int n; while(~scanf("%d",&n)&&n) { int i,j,t = 0; for(i = 1 ; i <= n ; i ++) scanf("%lf%lf%lf%lf",&f[i].x1,&f[i].y1,&f[i].x2,&f[i].y2); for(i = 1 ; i < n ; i ++) for(j = i+1 ; j <= n ; j ++) { if(find(f[i],f[j])) //判定每一次是否相交 t++; } printf("%d\n",t); } return 0;}
0 0
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu/hdoj 1086 You can Solve a Geometry Problem too
- hdu-1086You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU 1086:You can Solve a Geometry Problem too
- HDU 1086You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- HDU-1086-You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU-1086 You can Solve a Geometry Problem too
- HDU-1086-You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- 持续学习内容
- Android中为PopupWindow设置半透明背景的方案(兼容华为手机)
- 虚拟机的MAC地址分配与修改
- 关于WMTS服务的一些总结和疑问
- hibernate核心API简介
- HDU 1086 You can Solve a Geometry Problem too
- jvm性能监控和故障处理
- 一个在线的command line for linux
- WebBench学习使用
- 使用eclipse+pydev远程调试OpenStack
- java基础(5) 数组的操作
- mysql主从 1061 log同步错误处理
- 常用插件 for Xcode
- Pick-up sticks(线段相交判断)