Codeforces Round #261 (Div. 2)
A. Pashmak and Garden
time limit per test
1 second memory limit per test
256 megabytes input
standard input output
standard output Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Sample test(s)
Input
0 0 0 1 Output
1 0 1 1 Input
0 0 1 1 Output
0 1 1 0 Input
0 0 1 2 Output
-1 |
题意:已知正方形的2个顶点的位置,求另外两个顶点的位置。(多解随意输出其中一种)
题解:认真考虑各种情况就好了。
主要看x差值和y差值,设dx=abs(x0-x1),dy=abs(y1-y0),考虑:
1.dx=dy=0的情况,不能成正方形。
2.dx=0,dy!=0的情况,怒成正方形,另外两个顶点就是把x移动dy就行。
3.dx!=0,dy=0,和2差不多。
3.dx!=0,dy!=0的情况,若dx!=dy则成不了正方形,若=,则可以成,另外两个点是(x1,y0) (x0,y1)
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) prllf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair int a[],b[]; bool farm(){
if(a[]-a[]==){
if(b[]-b[]==)return ;
a[]=a[]+b[]-b[];
a[]=a[];
b[]=b[];
b[]=b[];
return ;
}else{
if(b[]-b[]==){
b[]=b[]+a[]-a[];
b[]=b[];
a[]=a[];
a[]=a[];
return ;
}
if(abs(b[]-b[])!=abs(a[]-a[]))return ;
a[]=a[];
a[]=a[];
b[]=b[];
b[]=b[];
return ;
}
} int main(){
scanf("%d%d%d%d",&a[],&b[],&a[],&b[]);
bool ans=farm();
if(ans)printf("%d %d %d %d\n",a[],b[],a[],b[]);
else puts("-1");
return ;
}