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

UVA - 10250

The Other Two Trees

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

Submit Status

Description

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;
} 
时间: 2024-08-24 20:25:00

UVA - 10250 - The Other Two Trees (简单计算几何)的相关文章

UVa 10250 The Other Two Trees

还是读了很长时间的题,不过题本身很简单. 可以把四棵树想象成正方形的四个顶点,已知两个相对顶点的坐标,求另外两个坐标. 不过,原题可没直接这么说,中间需要一些小证明. 题中说有一个平行四边形然后分别以四条边为边长向外作正方形,四棵树就在四个正方形中心的位置. 这是我用几何画板画的图. 下面证△FOE≌△HGO 设CD=2a,BC=2b ∴EF=OH=a, OF=HG=b 易知∠DFO=∠OHB ∴∠EFO=∠OHG=∠DFO+90° ∴△FOE≌△HGO(边角边) ∴∠E=∠GOH ∠EOG=∠

[HDU 4082] Hou Yi&#39;s secret (简单计算几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多少个,更新答案. 代码: 1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <cstring> 5 #include <vector> 6 #includ

UVA - 10905 - Children&#39;s Game (简单排序)

UVA - 10905 Children's Game Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description 4thIIUCInter-University Programming Contest, 2005 A Children's Game Input: standard input Output: standard output Problems

POJ 1556 The Doors(简单计算几何+最短路)

●赘述题目 10*10的房间内,有竖着的一些墙(不超过18个).问从点(0,5)到(10,5)的最短路. 按照输入样例,输入的连续5个数,x,y1,y2,y3,y4,表示(x,0--y1),(x,y2--y3),(x,y4--10)是墙壁. ●题解 方法:建图(用到简单计算几何)+最短路 ○记录下每个端点. ○包含起点,终点,以及每个墙的可以走的端点,如下图: ○然后枚举点,尝试两两组合连(线段)边,若该线不会撞在墙上,即不会与墙壁线段相交,就add_adge(). 效果图如下: 如何判断呢?

UVA 12714 Two Points Revisited(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4452 题意: 给出两个点组成一条直线,要你任意输出两个点,要求这两点组成的直线和给出的直线垂直(注意输出的点不能有负数): 代码如下: #include <cstdio> int main(

uva 10020- Minimal coverage (贪心思想 简单区间覆盖)

题目大意:给出一个范围M,然后给出若干的区间,以0 0 终止, 要求用最少的区间将0 ~M 覆盖,输出最少个数以及方案. 解题思路:典型的区间覆盖问题,算法竞赛入门经典P154上有讲. /*author: charkj_z */ /*time: 0.108s */ /*rank: 674 */ /*为什么不把没用的地方去掉? 因为去掉了我觉得不像我能写出来的*/ /*Ac code : */ #include<stdio.h> #include<string.h> #include

uva 11178 Morley&amp;#39;s Theorem(计算几何-点和直线)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

ACM学习历程—HDU1392 Surround the Trees(计算几何)

Description There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him?        The

HDU2948Geometry Darts(简单计算几何)

题目大意就是说两个人掷飞镖,飞镖在所给定的图形内就记一分,现在给定N个图形(圆.三角形和矩形),问每一次比赛(没人分别掷三次)谁赢. 1 #include <map> 2 #include <set> 3 #include <stack> 4 #include <queue> 5 #include <cmath> 6 #include <ctime> 7 #include <vector> 8 #include <c