straight line

Using the slope-intercept + slope sentence words to Patent infinite case, the processing accuracy.

If the can are integers from about Sharing the triples.

struct _ {
	int a,b,c;
	bool operator < (const _ &rhs) const {
		if (a!=rhs.a) return a<rhs.a;
		if (b!=rhs.b) return b<rhs.b;
		return c<rhs.c;
	}
};

_ get(pii a, pii b) {
	int A = b.y-a.y, B = a.x-b.x, C = -A*a.x-B*a.y;
	if (!A&&!C) return {0,1,0};
	if (!B&&!C) return {1,0,0};
	if (!C) {
		if (A<0) A=-A,B=-B,C=-C;
		int g = gcd(A,abs(B));
		return {A/g,B/g,0};
	}
	if (!B) {
		if (A<0) A=-A,B=-B,C=-C;
		int g = gcd(A,abs(C));
		return {A/g,0,C/g};
	}
	if (!A) {
		if (B<0) A=-A,B=-B,C=-C;
		int g = gcd(B,abs(C));
		return {0,B/g,C/g};
	}
	if (A<0) A=-A,B=-B,C=-C;
	int g = gcd(gcd(A,abs(B)),abs(C));
	return {A/g,B/g,C/g};
}

 

Guess you like

Origin www.cnblogs.com/uid001/p/10951374.html