POJ 1269
2017-04-13 13:32
239 查看
code:
#include <cmath> #include <cstdio> #include <utility> using namespace std; typedef double ld; int n; struct Point{ int x, y; void read(){ scanf("%d%d", &x, &y); } }s1, e1, s2, e2; typedef pair<pair<int, int>, int> Line; Line a, b; bool operator == (pair<int, int> &a, pair<int, int> &b){ return a.first == b.first && a.second == b.second; } inline int gcd(int a, int b){return b ? gcd(b, a % b) : a;} Line getLine(Point &a, Point &b){ if(a.x == b.x) return make_pair(make_pair(0, 0), a.x); if(a.y == b.y) return make_pair(make_pair(1, 0), a.y); int dx = a.x - b.x, dy = a.y - b.y; if(dx < 0){ dx *= -1; dy *= -1; } int d = gcd(abs(dx), abs(dy)); dx /= d; dy /= d; int v = (a.y % dy + dy) % dy; v = a.x + (v - a.y) / dy * dx; return make_pair(make_pair(dx, dy), v); } int main(){ puts("INTERSECTING LINES OUTPUT"); scanf("%d", &n); while(n--){ s1.read(); e1.read(); s2.read(); e2.read(); a = getLine(s1, e1); b = getLine(s2, e2); if(a.first == b.first){ if(a.second == b.second) puts("LINE"); else puts("NONE"); }else{ if(a.first == make_pair(0, 0)){ ld k2 = (ld)b.first.second / b.first.first; ld b2 = (ld)s2.y - k2 * s2.x; printf("POINT %.2lf %.2lf\n", (ld)s1.x, s1.x * k2 + b2); }else{ if(b.first == make_pair(0, 0)){ ld k1 = (ld)a.first.second / a.first.first; ld b1 = (ld)s1.y - k1 * s1.x; printf("POINT %.2lf %.2lf\n", (ld)s2.x, s2.x * k1 + b1); } else{ ld k1 = (ld)a.first.second / a.first.first; ld b1 = (ld)s1.y - k1 * s1.x; ld k2 = (ld)b.first.second / b.first.first; ld b2 = (ld)s2.y - k2 * s2.x; ld x = (b2 - b1) / (k1 - k2); printf("POINT %.2lf %.2lf\n", x, x * k1 + b1); } } } } puts("END OF OUTPUT"); return 0; }
相关文章推荐
- poj 1269 Intersecting Lines
- [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ1269 计算几何直线与直线的关系
- POJ 1269 Intersecting Lines(计算几何 直线交点 点在直线上 直线平行)
- POJ 1269
- Poj 1269
- (计算几何step8.1.2.2)POJ 1269 Intersecting Lines(使用叉积来计算两条直线的交点)
- POJ-1269判断线与线的关系
- POJ 1269(计算几何+直线相交)
- 【POJ 1269 Intersecting Lines】+ 线段相交
- poj 1269(两条直线交点)
- POJ 1269 Intersecting Lines(计算几何)
- poj 1269Intersecting Lines (直线相交判断,求相交交点)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- poj 1269 Intersecting Lines
- poj 1269 知识点:直线相交判断,求相交交点
- POJ 1269 Intersecting Lines
- POJ 1269 Intresting Lines(直线之间的关系及求交点)