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代码:
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int main(void)
{
#ifdef LOCAL
freopen("10250in.txt", "r", stdin);
#endif double x[], y[], midx, midy;
while(scanf("%lf %lf %lf %lf", &x[], &y[], &x[], &y[]) == )
{
midx = (x[] + x[]) / ;
midy = (y[] + y[]) / ;
x[] = midx + midy - y[];
y[] = x[] - midx + midy;
x[] = midx - midy + y[];
y[] = midx + midy - x[];
printf("%.10lf %.10lf %.10lf %.10lf\n", x[], y[], x[], y[]);
}
return ;
}
代码君
UVa 10250 The Other Two Trees的更多相关文章
- 【例题 6-17 UVa 10562】Undraw the Trees
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟+递归 [代码] #include <bits/stdc++.h> using namespace std; con ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)
Count the Trees Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...
- UVA.122 Trees on the level(二叉树 BFS)
UVA.122 Trees on the level(二叉树 BFS) 题意分析 给出节点的关系,按照层序遍历一次输出节点的值,若树不完整,则输出not complete 代码总览 #include ...
- UVa 10562 Undraw the Trees 看图写树
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...
随机推荐
- javascript和swf在网页中交互的一些总结
Javascript和swf在网页中交互一般可有以下几种情况: 1.swf和这些调用的javascript在同域 2.swf和这些调用的javascript在不同域,比如加载远程的swf然后call别 ...
- LCA(最近公共祖先)离线算法Tarjan+并查集
本文来自:http://www.cnblogs.com/Findxiaoxun/p/3428516.html 写得很好,一看就懂了. 在这里就复制了一份. LCA问题: 给出一棵有根树T,对于任意两个 ...
- Android线程消息通信(一)
Android在Java标准线程模型的基础上,提供了消息驱动机制,用于多线程之间的通信.基于消息驱动机制的线程通信模型陈伟线程消息通信.在标准线程模型中,线程执行完毕后便退出,而Android扩展了线 ...
- JS中的内部类
js内部类 javascript中本身有提供一些可以直接使用的类,这种类就是内部类.主要有:Object.Array.Math.Boolean.String.Number.Date.RegExp. ...
- VS2013试用期结束后如何激活
在激活框中输入密钥:BWG7X-J98B3-W34RT-33B3R-JVYW9
- 如何成为高级java程序员
或许您已经读过我的那篇小文<如何成为java初级程序员>,那里面只介绍了成为一个JAVA程序员应该具备的一些知识.我相信您绝不会只想着做一个初级的程序员,上了软件开发的小船,您肯定有着远大 ...
- mq_close
NAME mq_close - 关闭一个消息队列 (REALTIME) SYNOPSIS #include <mqueue.h>int mq_close(mqd_t mqdes) DESC ...
- 超级内存NVDIMM
1.序言 基于非易失性内存(NVDIMM)的新一代内存条规格已经研制成功,其中集成了DRAM和非易失性存储芯片,能够在完全断电的时候完整保存内存数据,并支持主内存在持久高速高性能计算上的应用.区别于普 ...
- Centos环境下部署游戏服务器-自动化
计算机是没有智力的,只会接受指令,运行指令,得出结果.因此就算你让它重复做一件事多少次,它也学不会自动去做这件事.对于重复繁琐的事情,做为一个懒惰的程序员,必须告诉机器去做这件事情,然后就行了,而不是 ...
- HighCharts开发说明及属性详解
一.HighCharts开发说明: HighCharts 开发实际上配置HighCharts每个部分,比如配置标题(title),副标题(subtitle)等,其中每个部分又有更细的参数配置,比如标题 ...