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=∠EOF+∠DFO+∠E=90°      (因为再加上∠DFE就等于内角和180°了)

综上,OE=OG且OE⊥OG

由于对称性,四棵树就构成了个正方形。

下面说说算法,利用旋转。我是用复数做的。

比如说一个复平面的向量a+bi乘上i所得向量就是逆时针旋转90°所得向量,乘上-i就是顺时针。

可以计算出中点O的坐标,然后向量OG=Gx-Ox+(Gy-Oy)i,乘上单位向量i得Oy-Gy+(Gx-Ox)i。

在加上O的坐标就得到E的坐标(Ox+Oy-Gy,Oy-Ox+Gx)。

同理也可以很容易求出顺时针转90°后点的坐标。

10250

Problem E

The Other TwoTrees

Input: standard input

Output: standard output

Time Limit: 2 seconds

You have a quadrilateral(四边形) shaped land whose opposite fences are ofequal length(四边形对边相等,也就是平行四边形). You have four neighborswhose lands are exactly adjacent(邻近的) to your four fences, that means you have acommon fence with all of them. For example if you have a fence of length d inone side, this fence of length d is also the fence of theadjacent neighbor on that side. The adjacent neighbors have no fence in commonamong themselves and their lands also don’t intersect(相交). The main difference between their land andyour land is that their lands are all square(正方形) shaped. All your neighbors have a tree at the center oftheir lands. Given the Cartesian coordinates(笛卡尔坐标) of trees of two opposite neighbors, you will have tofind the Cartesian coordinates of the other two trees.

Input

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

Output

For each line of input produce one line ofoutput which contains the line “Impossible.” without thequotes, if you cannot determine the coordinates of the other two trees.Otherwise, print four floating point numbers separated by a single space withten digits after the decimal point ax1, ay1, ax2, ay2, where (ax1,ay1)  and (ax2, ay2) are the coordinates of the othertwo trees. The output will be checked with special judge program, so don’tworry about the ordering of the points or small precision errors. The sampleoutput will make it clear.

Sample Input

10 0 -10 0

10 0 -10 0

10 0 -10 0

Sample Output

0.000000000010.0000000000 0.0000000000 -10.0000000000

0.000000000010.0000000000 -0.0000000000 -10.0000000000

0.0000000000-10.0000000000 0.0000000000 10.0000000000


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

AC代码:

 1 //#define LOCAL
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6
 7 int main(void)
 8 {
 9     #ifdef LOCAL
10         freopen("10250in.txt", "r", stdin);
11     #endif
12
13     double x[4], y[4], midx, midy;
14     while(scanf("%lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1]) == 4)
15     {
16         midx = (x[0] + x[1]) / 2;
17         midy = (y[0] + y[1]) / 2;
18         x[2] = midx + midy - y[0];
19         y[2] = x[0] - midx + midy;
20         x[3] = midx - midy + y[0];
21         y[3] = midx + midy - x[0];
22         printf("%.10lf %.10lf %.10lf %.10lf\n", x[2], y[2], x[3], y[3]);
23     }
24     return 0;
25 }

代码君

UVa 10250 The Other Two Trees

时间: 2024-11-07 10:14:49

UVa 10250 The Other Two Trees的相关文章

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

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

计划,,留

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 一.<算法竞赛入门经典> 刘汝佳 (UVaOJ 351道题) 以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html "AOAPC I"

算法竞赛入门经典+挑战编程+USACO

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发.   一.UVaOJ http://uva.onlinejudge.org  西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ.   二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html   "AO

(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html “AOAPC I”是刘汝佳(大

UVa 10562 Undraw the Trees 看图写树

转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将这些树转换成特定的括号表示的树 思路: 首先,观察样例,可以发现就是先序遍历的顺序,因此可以确定dfs 但是,还有几个地方需要考虑: 同一级的结点,在同一级的括号中 由于顺序满足先序遍历,因此不需要存储树,更不需要构建树,直接在遍历过程中输出即可. 空树:即输入为:# 时的树的处理,我不建议在此进行

Undraw the Trees (Uva 10562)

题意:将多叉树转化为括号表示法.每个结点用除了‘-’, ‘|’, ‘ ’(空格), ‘#’ 的其他字符表示,每个非叶结点的正下方会有一个 ‘|’ 字符,然后下面是一排 ‘-’ 字符,恰好覆盖所有子节点的上方.单独的一行 ‘#’ 为数据结束. 例样输入: 2  A  |--------B C   D    |   | ----- - E  F G#e|----f g# 例样输出: (A(B()C(E()F())D(G()))) (e(f()g())) 思路: 将输入数据存入二维数组,在二维数组中进

UVA 122 -- Trees on the level (二叉树 BFS)

 Trees on the level UVA - 122  解题思路: 首先要解决读数据问题,根据题意,当输入为"()"时,结束该组数据读入,当没有字符串时,整个输入结束.因此可以专门编写一个readin()函数,类型设置为bool型,遇到第一种情况时返回true,遇到第二种情况返回false,主程序中只要发现readin返回false时就break,结束整个大循环. 接下来要建立二叉树,首先为二叉树编写一个结构体,然后根据字符串的输入情况来建树,如果是'L'就往左走,走不动时建一颗

uva 122 trees on the level——yhx

题目如下:Given a sequence of binary trees, you are to write a program that prints a level-order traversal of each tree. In this problem each node of a binary tree contains a positive integer and all binary trees have have fewer than 256 nodes. In a level