Ruined Square(计算几何)

问题 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.

  • 样例输入 Copy
    0 0 0 1

  • 样例输出 Copy
    -1 1 -1 0

  • 提示
    (0,0),(0,1),(−1,1),(−1,0) is the four vertices of a square in counter-clockwise order. Note that (x3,y3)=(1,1),(x4,y4)=(1,0) is not accepted, as the vertices are in clockwise order.

  • 题意分析 :就是有一个正方形,只知道它相邻的两个点,求逆时针的另两个点的坐标 。

  • 先说一下,我一开始的思路
    一开始想错了,这个实现就是A点在B左下可以,实现A点在B点的右上就会出错。当然可能能分类讨论,目前没分类

  • 思路:题意很简单,实现起来也简单,这个思路其实和那个差不多,我认为这是利用全等三角形之类的知识。就是1这个三角形与2这个三角形全等

  • xc就等于xb-(yb-ya);

  • 同样的 yc=yb+(xb-xa);

  • 知道c点的左边可以用B点和C点的坐标求出D点坐标;

在这里插入图片描述
代码:

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#define ll long long int
#define sc(a) scanf("%lld",&a)
const int mod=998244353;
using namespace std;
const int inf=1e9+7;
const int maxn=2e5+10;

ll n,m,sum,r,t,p,l;
ll a[maxn],b[maxn];
char str[maxn],s[maxn];

int main() {
	ll x2,y1,y2,x1,x3,x4,y3,y4;
	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\n",x3,y3,x4,y4);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值