Codeforces #261 (Div. 2) A. Pashmak and Garden(水题)

来源:互联网 发布:js 大于等于 小于等于 编辑:程序博客网 时间:2024/05/17 03:57

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 x1and 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



很水的一道题,给定两个点,判断能否再添加两个点构成一个正方形

只怪这个题数据给的不好,不然肯定可以跪掉一批人

如果把4个x y的范围都限定相同,那这场真的可以成为人生大赢家了可怜

严谨代码如下:

#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 10010#define LL long longusing namespace std;bool judge(int x) {    if(x>=-1000 && x<=1000)        return true;    return false;}int main(void) {    int x1, y1, x2, y2, x3, y3, x4, y4, tmp;    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);    if(x1 == x2)  {        tmp = abs(y2 - y1);        if(judge(x1+tmp))            printf("%d %d %d %d\n", x1+tmp, y1, x1+tmp, y2);        else if(judge(x1-tmp))            printf("%d %d %d %d\n", x1-tmp, y1, x1-tmp, y2);        else printf("-1\n");    } else if(y1 == y2) {        tmp = abs(x2 - x1);        if(judge(y1+tmp))            printf("%d %d %d %d\n", x1, y1+tmp, x2, y1+tmp);        else if(judge(y1-tmp)) {            printf("%d %d %d %d\n", x1, y1-tmp, x2, y1-tmp);        }        else printf("-1\n");    } else {        if(abs(y2-y1) != abs(x2-x1))            printf("-1\n");        else {            printf("%d %d %d %d\n", x1, y2, x2, y1);        }    }    return 0;}


0 0
原创粉丝点击