Ultraviolet A 10250-The Other Two Trees

Source: Internet
Author: User

Problem E

The Other Two Trees

Input: standard input

Output: standard output

Time Limit: 2 seconds

 

You have a quadrilateral shaped land whose opposite fences are of equal length. you have four neighbors whose lands are exactly adjacent to your four fences, that means you have a common fence with all of them. for example if you have a fence of length d in one side, this fence of lengthd is also the fence of the adjacent neighbor on that side. the adjacent neighbors have no fence in common among themselves and their lands also don't intersect. the main difference between their land and your land is that their lands are all square shaped. all your neighbors have a tree at the center of their lands. given the Cartesian coordinates of trees of two opposite neighbors, you will have to find the Cartesian coordinates of the other two trees.

 

Input
The input file contains several lines of input. each line contains four floating point or integer numbers x1, y1, x2, y2, where (x1, y1), (x2, y2) are the coordinates of the trees of two opposite neighbors. input is terminated by end of file.

 

Output
For each line of input produce one line of output which contains the line "Impossible. "without the quotes, if you cannot determine the coordinates of the other two trees. otherwise, print four floating point numbers separated by a single space with ten digits after the decimal point ax1, ay1, ax2, ay2, where (ax1, ay1) and (ax2, ay2) are the coordinates of the other two trees. the output will be checked with special judge program, so don't worry about the ordering of the points or small precision errors. the sample output will make it clear.

 

Sample Input
10 0-10 0

10 0-10 0

10 0-10 0

 

Sample Output
0.0000000000 10.0000000000 0.0000000000-10.0000000000

0.0000000000 10.0000000000-0.0000000000-10.0000000000

0.0000000000-10.0000000000 0.0000000000 10.0000000000


--------------------------------------------------------------------------------

(World Final Warm-up Contest, Problem Setter: Shahriar Manzoor)


================

2 ideas
This question is actually known the coordinate of Two Corner vertices of a square, and the other two coordinates are obtained. I thought it was not difficult, but I couldn't figure out how to solve it at the beginning. I drew a picture and looked at other people's ideas to understand it. It seems that I have learned mathematics for myself.

A picture is better than a thousand words:
 

 


Note that the four triangles in the diagram are completely equal, and the calculation process in the comparison diagram and code is easy to understand.

3 code,
 

#include <stdio.h>#include <math.h>#define EPS 1e-8int main() {  double x1,y1,x2,y2;  double ax1, ay1, ax2, ay2;  double a, b;  while (scanf ("%lf%lf%lf%lf", &x1, &y1, &x2, &y2) != EOF) {    if (fabs(x1-x2)<EPS && fabs(y1-y2)<EPS) {      printf ("Impossible.\n");      continue;    }    a = (y1-y2+x2-x1)/2;    b = (y1-y2-x2+x1)/2;    ax1 = x2 - a;    ay1 = y2 + b;    ax2 = x2 + b;    ay2 = y2 + a;    printf ("%.10lf %.10lf %.10lf %.10lf\n", ax1, ay1, ax2, ay2);  }  return 0;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.