POJ 1066 线段相交判断
来源:互联网 发布:数据库维护 编辑:程序博客网 时间:2024/05/16 10:38
题目链接:http://poj.org/problem?id=1066
题解:线段相交判断
要通过的“门”最少,也就是该点与边框点的连线也其他线段的交点最少。
#include<cstdio>#include<cmath>#include<algorithm>#define N 35using namespace std;//定义点struct Point{double x, y;Point(double x = 0, double y = 0) : x(x), y(y) {}};typedef Point Vector; //Vector 为 Point的别名//点-点=向量Vector operator - (Point A, Point B) {return Vector(A.x-B.x, A.y-B.y);}struct segment{ Point a, b;}seg[N];const double eps = 1e-10;int dcmp(double x){if(fabs(x) < eps) return 0;else return x < 0 ? -1 : 1;}//叉积:两向量v和w的叉积等于v和w组成的三角形的有向面积的两倍 XaYb - XbYadouble Cross(Vector A, Vector B){return A.x*B.y - A.y*B.x;}//每条线段的两个端点都在另一条线段的两侧bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2)//a,b线段{double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1), c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1);return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4) < 0;}int main (){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%lf %lf %lf %lf", &seg[i].a.x, &seg[i].a.y, &seg[i].b.x, &seg[i].b.y); } Point final; scanf("%lf %lf", &final.x, &final.y); int ans = 1000; for(int i = 1; i <= n; i++) { int cnt = 0; for(int j = 1; j <= n; j++) if(SegmentProperIntersection(seg[j].a, seg[j].b, final, seg[i].a)) cnt++; ans = min(cnt, ans); cnt = 0; for(int j = 1; j <= n; j++) if(SegmentProperIntersection(seg[j].a, seg[j].b, final, seg[i].b)) cnt++; ans = min(cnt, ans); } if(n == 0) printf("Number of doors = 1\n"); else printf("Number of doors = %d\n", ans+1); return 0;}
1 0
- POJ 1066 判断线段相交
- POJ 1066 线段相交判断
- poj 1066 Treasure Hunt(判断线段相交)
- POJ 1066 Treasure Hunt(线段相交判断)
- POJ 1066 Treasure Hunt(线段相交判断)
- poj 1066 判断线段相交 思维
- POJ 2653 判断线段相交
- POJ 2653 判断线段相交
- POJ 2653 (判断线段相交)
- Poj-1066 (判断线段与线段是否相交)
- POJ 1066 线段相交
- POJ 1066 线段相交
- POJ 1066 线段相交
- poj 1066 Treasure Hunt(判断线段相交)
- poj 1066 Treasure Hunt(判断线段相交)
- POJ 1066 Treasure Hunt 判断两线段是否相交
- POJ 1066 Treasure Hunt (判断线段相交个数)
- poj 1066 Treasure Hunt(判断线段相交)
- C++的一点基本自我修养(一)
- git学习六(git merge --squash)
- java 实现https请求
- 【编程好习惯】精确包含头文件
- s3c2440硬件学习笔记----内存管理单元MMU
- POJ 1066 线段相交判断
- MSSQL2005查询表中字段的描述
- UILocalizedIndexedCollation 的浅分析
- Android属性
- 谷歌分析iOS开发包实战
- HDU 4731 Minimum palindrome
- 利用SQLDMO备份和还原数据库
- android:windowSoftInputMode属性使用
- 收到csdn的一个技术峰会的邮件,主题全是乱码。