B. Parallelogram is Back
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.
Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.
Input
The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.
Output
First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.
Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.
Example
input
0 0
1 0
0 1
output
3
1 -1
-1 1
1 1
Note
If you need clarification of what parallelogram is, please check Wikipedia page:
https://en.wikipedia.org/wiki/Parallelogram
<Solution>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <iostream> using namespace std; struct Cpoint { double X; double Y; }; int main() { struct Cpoint p1, p2, p3, p4; cin >> p1.X; cin >> p1.Y; cin >> p2.X; cin >> p2.Y; cin >> p3.X; cin >> p3.Y; cout << "3" << endl; p4.X = (p1.X + p2.X) - p3.X; p4.Y = (p1.Y + p2.Y) - p3.Y; cout << p4.X << " " << p4.Y << endl; p4.X = (p2.X + p3.X) - p1.X; p4.Y = (p2.Y + p3.Y) - p1.Y; cout << p4.X << " " << p4.Y << endl; p4.X = (p1.X + p3.X) - p2.X; p4.Y = (p1.Y + p3.Y) - p2.Y; cout << p4.X << " " << p4.Y; return 0; } | cs |
<Online Solution>
http://codeforces.com/blog/entry/49186#comments
Denote the input points as A, B, C, and the point we need to find as D.
Consider the case when the segments AD and BC are the diagonals of parallelogram. Vector AD is equal to the sum of two vectors AB + BD = AC + CD. As in the parallelogram the opposite sides are equal and parallel, BD = AC, AB = CD, and we can conclude that AD = AB + AC. So, the coordinates of the point D can be calculated as A + AB + AC = (Ax + Bx - Ax + Cx - Ax, Ay + By - Ay + Cy - Ay) = (Bx + Cx - Ax, By + Cy - Ay).
The cases where the diagonals are BD and AC, CD and AB are processed in the same way.
Prove that all three given points are different. Let's suppose it's wrong. Without losing of generality suppose that the points got in cases AD and BD are equal.
Consider the system of two equations for the equality of these points:
- Bx + Cx - Ax = Ax + Cx - Bx
- By + Cy - Ay = Ay + Cy - By
We can see that in can be simplified as
And we got a contradiction, as all the points A, B, C are distinct.