首页 > 其他 > 详细

UVa 10250 The Other Two Trees

时间:2014-01-31 14:20:49      阅读:523      评论:0      收藏:0      [点我收藏+]

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 length d 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 pointax1, 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)

 

由题意很容易发现,四棵苹果树构成了一个正方形。

由给定的两个点,先求出中点,再求出由这两个点确定的向量,将这个向量逆时针旋转90度再除以二,加到中点上去即可求出正方形的另外两个点

向量(x,y)逆时针旋转90度变为(-y,x)

 

bubuko.com,布布扣
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     double x1,y1,x2,y2,ax1,ay1,ax2,ay2,mx,my,vx,vy;
10 
11     while(scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2)==4)
12     {
13         if(x1>=x2)
14         {
15             swap(x1,x2);
16             swap(y1,y2);
17         }
18 
19         mx=(x1+x2)/2;
20         my=(y1+y2)/2;
21         vx=(x2-x1)/2;
22         vy=(y2-y1)/2;
23 
24         swap(vx,vy);
25         vx=-vx;
26 
27         ax1=mx+vx;
28         ay1=my+vy;
29 
30         ax2=mx-vx;
31         ay2=my-vy;
32 
33         printf("%.10f %.10f %.10f %.10f\n",ax1,ay1,ax2,ay2);
34     }
35 
36     return 0;
37 }
[C++]

UVa 10250 The Other Two Trees

原文:http://www.cnblogs.com/lzj-0218/p/3536724.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!