Problem describe
In the heart of your home city, there is an old square, close to the train station, appropriately called Station Square. It used to look like a perfect square: four sides of equal length joined by right angles. However, it hasn’t looked like this for decades, as one of the four corners was destroyed by bombings in the Second World War. After the war, the square was rebuilt as a quarter circle, and it has looked like that ever since. (In other words, it looks like an isosceles right triangle, except that the hypothenuse is not a straight line but a circular arc.) This is illustrated in the figure below, which corresponds with Sample Input 1.
Figure 1: Illustration of the first example input.
Recently, the city council voted to completely remodel the train station and its surroundings, which includes restoring Station Square to its original state. Therefore they need to determine the exact location of the fourth corner. This task is too complicated for ordinary aldermen, so the city decided to hire a top scientist. That would be you! Please help the city complete the square, and you will be greatly rewarded!
Input
There are three lines of input. Each line contains two integers denoting the xx and yy coordinates of one of the corners of the current square − 1 0 4 ≤ x , y ≤ 1 0 4 -10^4 \leq x,y\leq 10^4 −104≤x,y≤104
Output
Output one line with two space-separated integers denoting the xx and yy coordinates of the long-lost fourth corner.
思路
此题本质是知矩形的三点坐标,求另一点坐标
x 4 = x 2 + x 3 − x 1 x4=x2+x3-x1 x4=x2+x3−x1
y 4 = y 2 + y 3 − y 1 y4=y2+y3-y1 y4=y2+y3−y1其中:点4为未知数,点1为已知的直角顶点
#include<cstdio>
struct zuobiao {
int x,y; };
zuobiao qiudian(int x1,int y1,int x2,int y2,int x3,int y3) {
zuobiao g;
g.x=x1+x3-x2;g.y=y1+y3-y2;
return g;
}
int main() {
int x1,y1,x2,y2,x3,y3;
zuobiao g;
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
if((x1-x2)*(x2-x3)+(y1-y2)*(y2-y3)==0) g=qiudian(x1,y1,x2,y2,x3,y3);
if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)==0) g=qiudian(x1,y1,x3,y3,x2,y2);
if((x1-x3)*(x2-x1)+(y1-y3)*(y2-y1)==0) g=qiudian(x3,y3,x1,y1,x2,y2);
printf("%d %d",g.x,g.y);
return 0; }