复变函数考试真闹心!!!
水题不解释。
#include <iostream>
#include <vector> #include <algorithm> #include <math.h> #include <stdio.h> using namespace std; #define eps 1e-8 #define zero(x) (((x)>0?(x):-(x))<eps) struct point { double x, y; }; struct line { point a, b; int index; } temp; double xmult(point p1, point p2, point p0) { return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y); } int dots_inline(point p1, point p2, point p3) { return zero(xmult(p1, p2, p3)); } int same_side(point p1, point p2, line l) { return xmult(l.a, p1, l.b)*xmult(l.a, p2, l.b)>eps; } int dot_online_in(point p, line l) { return zero(xmult(p, l.a, l.b)) && (l.a.x - p.x)*(l.b.x - p.x)<eps && (l.a.y - p.y)*(l.b.y - p.y)<eps; } int intersect_in(line u, line v){ if (!dots_inline(u.a, u.b, v.a) || !dots_inline(u.a, u.b, v.b)) return !same_side(u.a, u.b, v) && !same_side(v.a, v.b, u); return dot_online_in(u.a, v) || dot_online_in(u.b, v) || dot_online_in(v.a, u) || dot_online_in(v.b, u); } bool judge(line t) { return intersect_in(t, temp); } vector<line> v; int main() { int n; while (~scanf("%d", &n) && n) { v.clear(); for (int i = 1; i <= n; i++) { scanf("%lf%lf%lf%lf", &temp.a.x, &temp.a.y, &temp.b.x, &temp.b.y); temp.index = i; v.erase(remove_if(v.begin(), v.end(), judge), v.end()); v.push_back(temp); } cout << "Top sticks: "; for (vector<line>::iterator it = v.begin(); it != v.end(); it++) { cout << (*it).index; if (it != v.end() - 1) cout << ", "; else cout << "." << endl; } } } |