Uva 10250 - The Other Two Trees
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)
#include<stdio.h> #include<math.h> int main() { double x1, y1, x2, y2, temp, midx, midy, x3, y3, x4, y4, temp1, temp2; while(scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2) != EOF) { if(x1 == x2 && y1 == y2) { printf("Impossible.\n"); continue; } midx = (x1+x2)/2, midy = (y1+y2)/2; temp1 = (x1 - midx)*(x1 - midx) + (y1 - midy)*(y1 - midy); temp2 = temp1/(((y1-y2)/(x1-x2))*((y1-y2)/(x1-x2))+1); y3 = sqrt(temp2) + midy, y4 = -sqrt(temp2) + midy; x3 = midx - ((y1-y2)/(x1-x2))*sqrt(temp2); x4 = midx + ((y1-y2)/(x1-x2))*sqrt(temp2); printf("%.10lf %.10lf %.10lf %.10lf\n", x3, y3, x4, y4); } return 0; }
解题思路:
读题真的占去了大半的时间,后来缩减后得到的信息是:给你正方形两个对顶顶点的坐标,求另外两个顶点的坐标,因为根据题目背景的意思,给你的两棵树之间的距离跟另外两棵树之间所成的线是垂直的,这是其一,其二是:尽管你的院子是非正方形的矩形,但到附近其中一个院子的距离是 (长/2 + 宽/2) 而到旁边的那个院子的距离是 (宽/2 + 长/2) 只是路径不一样,最后的长度还是一样的,这就是简化后得到信息的原因
对于求解的问题,这就已经是高中的知识了

更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?