这个问题比较容易,写这篇文章的目的在于记录模板
#include <bits/stdc++.h> using namespace std; inline int read(){ int x = 0, f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c=getchar();} return x*f; } const double eps = 1e-8; const int MAXN = 1e6 + 100; int sgn(double x){ if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } struct Point{ double x, y; Point(){} Point(double x, double y): x(x), y(y){} bool operator == (const Point &B)const{ return x == B.x && y == B.y; } Point operator - (const Point &B)const{ return Point(x - B.x, y - B.y); } }s[MAXN]; typedef Point Vector; double Cross(Vector A, Vector B){ return A.x * B.y - A.y * B.x; } double distance(Point A, Point B){ return hypot(A.x - B.x, A.y - B.y); } void solve(){ double a, b; a = 1.0 * read(); b = 1.0 * read(); double p = 0.0; for(int i=0;i<3;i++){ if(Point(a, b) == s[i]){ cout << 4; return; } p += distance(s[i], s[(i + 1) % 3]); } p /= 2; for(int i=0;i<3;i++){ if(sgn(distance(s[i], s[(i + 1) % 3]) - distance(Point(a, b), s[i]) - distance(Point(a, b), s[(i + 1) % 3])) == 0){ cout << 3; return; } } double S2 = 0.0; double x = distance(s[0], s[1]); double y = distance(s[1], s[2]); double z = distance(s[2], s[0]); double S = sqrt(p * (p - x) * (p - y) * (p - z)); for(int i=0;i<3;i++){ S2 += fabs(Cross(Point(a, b) - s[i], Point(a, b) - s[(i + 1) % 3])); } S2 /= 2; if(sgn(S - S2) == 0) cout << 1; else if(sgn(S - S2) < 0) cout << 2; } int main(){ for(int i=0;i<3;i++){ s[i].x = 1.0 * read(); s[i].y = 1.0 * read(); } solve(); return 0; }