poj 1296 Noise Effect(判断线段相交,并求交点)
来源:互联网 发布:数据库物理模型主键 编辑:程序博客网 时间:2024/04/30 18:04
//以下为原blog搬迁过来的内容
【题目大意】:给出n组数据,每组数据四个数描述两条直线,判断直线重合,平行,或者相交。
【解题思路】:按照重合,平行,相交的顺序依次判断就是。主要是为了测试计算几何模版
【代码】:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <string>#include <cctype>#include <map>#include <iomanip> using namespace std; #define eps 1e-8#define pi acos(-1.0)#define inf 1<<30#define pb push_back#define lc(x) (x << 1)#define rc(x) (x << 1 | 1)#define lowbit(x) (x & (-x))#define ll long longstruct Point{ double x,y; Point() {} Point (double a,double b) { x=a,y=b; }}point[8];struct Line{ Point a,b; Line() {} Line(Point x,Point y) { a=x,b=y; }}line[2];inline int sig(double k) { return k < -eps ? -1 : k > eps;}inline double det(double x1, double y1, double x2, double y2){ return x1 * y2 - x2 * y1;}inline double xmult(Point o, Point a, Point b){ return det(a.x - o.x, a.y - o.y, b.x - o.x, b.y - o.y);}void getline(const Point &x, const Point &y, double &a, double &b, double &c){ a = y.y - x.y; b = x.x - y.x; c = y.x * x.y - x.x * y.y;}inline bool parallel(Line u,Line v){ return sig((u.a.x-u.b.x)*(v.a.y-v.b.y)-(v.a.x-v.b.x)*(u.a.y-u.b.y))==0;}inline bool sameline(Line u,Line v){ if (sig(xmult(u.a,v.a,v.b))==0 && sig(xmult(u.b,v.a,v.b))==0) return true; else return false;}Point intersect(double a1, double b1, double c1, double a2, double b2, double c2){ Point ret; ret.y = (a1 * c2 - c1 * a2) / (b1 * a2 - a1 * b2); if (sig(a2) == 0) ret.x = -(b1 * ret.y + c1) / a1; else ret.x = -(b2 * ret.y + c2) / a2; return ret;}int main(){ int T; scanf("%d",&T); printf("INTERSECTING LINES OUTPUT\n"); while (T--) { double p,q; for (int i=0; i<=3; i++) { scanf("%lf%lf",&p,&q); point[i]=Point(p,q); } line[0]=Line(point[0],point[1]); line[1]=Line(point[2],point[3]); double a1,a2,b1,b2,c1,c2; getline(line[0].a,line[0].b,a1,b1,c1); getline(line[1].a,line[1].b,a2,b2,c2); if (sameline(line[0],line[1])==true) printf("LINE\n"); else { if (parallel(line[0],line[1])==true) printf("NONE\n"); else { Point p1; p1=intersect(a1,b1,c1,a2,b2,c2); printf("POINT %.2lf %.2lf\n",p1.x,p1.y); } } } printf("END OF OUTPUT\n"); return 0;}
- poj 1296 Noise Effect(判断线段相交,并求交点)
- poj 1269 Intersecting Lines(判断线段相交,并求交点)
- 判断线段相交并求交点
- 判断两线段相交,并求交点
- 判断两条线段/直线相交,并求交点
- 判断两条线段/直线相交,并求交点
- 判断两线段是否相交,并求交点
- poj 1269 判断直线相交,并求交点
- POJ1039Pipe【线段相交判断+求交点】
- 判断两线段是否相交求交点
- [poj 1039]Pipes[线段相交求交点]
- 判断线段是否相交...并求出交点。
- uva 303 pipe (求线段交点,判断线段相交)
- POJ 1066 Treasure Hunt 判断线段相交(求交点个数)
- POJ 1039 Pipe(直线和线段相交判断,求交点)
- poj 1269 知识点:直线相交判断,求相交交点
- 求线段相交交点坐标
- 求射线与线段相交的最多交点 poj 4048
- android ListView美化-->几个比较特别的属性
- poj 2398 Toy Storage(判断点在多边形内,叉积)
- Android和iPhone应用程序界面布局示例
- poj 3304 Segments(利用叉积求是否存在直线与所给线段相交)
- configfs
- poj 1296 Noise Effect(判断线段相交,并求交点)
- 我们要有意识地增加网站中的关键词
- poj 1556 The Doors(最短路+判断线段相交)
- poj 2653 Pick-up sticks(判断线段是否相交)
- c中printf实现atoi实现
- poj 1066 Treasure Hunt(判断线段相交)
- poj 1410 Intersection(判矩形和线段相交。。细节多)
- poj 1696 Space Ant(叉积的性质,做极角排序)
- poj 3347 Kadj Squares(扩大数据运算的典型应用+映射)