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

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

解题思路:
直接看图!
在这里插入图片描述
AC代码:

#include <bits/stdc++.h>
#include <string.h> 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; 
    }

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

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值