题解 | 平分的直线
平分的直线
https://www.nowcoder.com/practice/e51af77572f74a5fa069b4d5a3a0953e
/*
struct Point {
    int x;
    int y;
    Point() :
            x(0), y(0) {
    }
    Point(int xx, int yy) {
        x = xx;
        y = yy;
    }
};*/
class Bipartition {
public:
    vector<double> getBipartition(vector<Point> A, vector<Point> B) {
        // write code here
        Point centerA = Point(A[0].x+ A[1].x +A[2].x + A[3].x, A[0].y+A[1].y + A[2].y+A[3].y);
        Point centerB = Point(B[0].x+ B[1].x +B[2].x + B[3].x, B[0].y+B[1].y + B[2].y+B[3].y);
      
        double k= (centerA.y - centerB.y +0.0) /(centerA.x -centerB.x);
        double b = (centerA.y  - centerA.x *k  )/4;
        return {k,b};
    }
};
海康威视公司福利 1144人发布
查看13道真题和解析