码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 10250 - The Other Two Trees (简单计算几何)

时间:2014-12-10 21:23:53      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:iostream   acm   icpc   计算几何   

UVA - 10250

Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

Submit Status

Description

bubuko.com,布布扣

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

Source

Root :: Prominent Problemsetters :: Shahriar Manzoor

Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: Maths - Simple Geometry
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: (Computational) Geometry :: Basic Geometry ::Points and Lines


题意: 就是给你正方形两个对顶顶点的坐标,求另外两个顶点的坐标


AC代码:



#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	double x1, y1, x2, y2;
	while(scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2)!=EOF)
	{
		if(fabs(x1-x2)<1e-7 && fabs(y1-y2)<1e-7)
		{
			printf("Impossible.\n");
			continue;
		}
		double midx, midy, x3, y3, x4, y4, t1, t2, k;
		midx = (x1 + x2) / 2; midy = (y1 + y2) / 2;
		t1 = (x1 - midx)*(x1 - midx) + (y1 - midy)*(y1 - midy);
		k = (y1-y2)/(x1-x2);   //对定点组成直线的斜率 
		t2 = t1 / (k*k + 1);    
		x3 = midx - k*sqrt(t2); x4 = midx + k*sqrt(t2);
		y3 = midy + sqrt(t2); y4 = midy - sqrt(t2);
		printf("%.10lf %.10lf %.10lf %.10lf\n", x3, y3, x4, y4);
	} 
	return 0;
} 





UVA - 10250 - The Other Two Trees (简单计算几何)

标签:iostream   acm   icpc   计算几何   

原文地址:http://blog.csdn.net/u014355480/article/details/41849325

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!