程序员面试金典——7.5平分的直线
Solution1:我的答案
/*
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
vector<double> line;
double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
for(int i = 0; i < 4; i++) {
x1 += A[i].x;
y1 += A[i].y;
x2 += B[i].x;
y2 += B[i].y;
}
x1 /= 4.0;
y1 /= 4.0;
x2 /= 4.0;
y2 /= 4.0;
line.push_back((y2-y1)/(x2-x1));
line.push_back((x2*y1-x1*y2)/(x2-x1));
return line;
}
};