【数学几何】已知正方形相邻两点的坐标,求另外两点的坐标

UPC contest2219 问题L:Ruined Square

比赛时想了很大一会没想出来,总觉得这个题不难,但始终差一点,比赛完听同学的一波思路,顿时开窍了,叹息一波。。。–>给我灵感的同学思路
题目描述:

There is a square in the xy-plane. The coordinates of its four vertices are (x1,y1),(x2,y2),(x3,y3) and (x4,y4) in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.)
Takahashi remembers (x1,y1) and (x2,y2), but he has forgot (x3,y3) and (x4,y4).
Given x1,x2,y1,y2, restore x3,y3,x4,y4. It can be shown that x3,y3,x4 and y4 uniquely exist and have integer values.
Constraints
·|x1|,|y1|,|x2|,|y2|≤100
·(x1,y1) ≠ (x2,y2)
·All values in input are integers.

输入:

Input is given from Standard Input in the following format:
x1 y1 x2 y2

输出:

Print x3,y3,x4 and y4 as integers, in this order.

样例输入:

0 0 0 1

样例输出:

-1 1 -1 0

解题思路:
直接看图!
【数学几何】已知正方形相邻两点的坐标,求另外两点的坐标_第1张图片
AC代码:

#include 
#include  using namespace std;
#define ll long long 
const int maxn=1e6+7; 
const int mod=1e9+7; int main(){
    ll x1,y1,x2,y2,x3,y3,x4,y4,i,j;
    cin >> x1 >> y1 >> x2 >> y2;
    x3=x2-(y2-y1);
    y3=y2+(x2-x1);
    x4=x3-(y3-y2);
    y4=y3+(x3-x2);
    printf("%lld %lld %lld %lld",x3,y3,x4,y4);
    return 0; 
    }

没错,就是这么简单!
当你决定了要向前迈进的那一刻,你就已经踏出前进的一步了。

你可能感兴趣的:(【数学几何】已知正方形相邻两点的坐标,求另外两点的坐标)