Ruined Square(计算几何)
Posted mb62d0ca5a0a625
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
#define"%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;
以上是关于Ruined Square(计算几何)的主要内容,如果未能解决你的问题,请参考以下文章