您的位置:首页 > 其它

UVa10250 – The Other Two Trees

2013-08-04 20:43 417 查看
Special Judge
 

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 din 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 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)
Problem Analysis

其实还真是挺水的。不过看到World Final Warm-up Contest还让我吃了一惊……

读懂题意之后,可以抽象为给定正方形的两个顶点,求另两个顶点。因为是一个Special Judge,所以就不用管各点顺序以及0前面是否要加符号的问题了。

直接在纸上画了几个图形,推导了一个公式(见程序)。交的时候没有写Impossible的情况,不过竟然过了。测试数据也挺神奇的。

在网上搜了一下别人的解题报告,觉得还是应该加上一句

C语言:
1 if(x1==x2&&y1==y2)
2  printf("Impossible.\n");

另外,看到一个向量旋转的定理。





(图片来自 uva code http://blog.csdn.net/frankiller/article/details/7725401

 

用起来貌似会简单点吧。

Word Learning

quadrilateral adj.四边(形)的 n.四边形

Cartesian n. 笛卡尔

Source Code

#include <stdio.h>
#include <math.h>
int main()
{
double x1,y1,x2,y2,x,y;
while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
{
if(x1==x2&&y1==y2)
printf("Impossible.\n");
else
{
x=(x1+x2)/2,y=(y1+y2)/2;
printf("%.10lf %.10lf %.10lf %.10lf\n",(y1-y)+x,-(x1-x)+y,(y2-y)+x,-(x2-x)+y);
}
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: