`
Simone_chou
  • 浏览: 195854 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

Rescue The Princess(数学)

 
阅读更多

Problem A:Rescue The Princess

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

 

Problem Description

      Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry  the princess set out immediately. Yet, the beast set a maze. Only if the prince find out the maze’s exit can he save the princess.

       Now, here comes the problem. The maze is a dimensional plane. The beast is smart, and he hidden the princess snugly. He marked two coordinates of an equilateraltriangle in the maze. The two marked coordinates are A(x1,y1) and B(x2,y2). The third coordinate C(x3,y3) is the maze’s exit. If the prince can find out the exit, he can save the princess. After the prince comes into the maze, he finds out the A(x1,y1) and B(x2,y2), but he doesn’t know where the C(x3,y3) is. The prince need your help. Can you calculate the C(x3,y3) and tell him?

 

Input

       The first line is an integer T(1 <= T <= 100) which is the number of test cases. T test cases follow. Each test case contains two coordinates A(x1,y1) and B(x2,y2), described by four floating-point numbers x1, y1, x2, y2( |x1|, |y1|, |x2|, |y2|<= 1000.0).

Please notice that A(x1,y1) and B(x2,y2) and C(x3,y3) are in an anticlockwise direction from the equilateral triangle. And coordinates A(x1,y1) and B(x2,y2) are given by anticlockwise.

 

Output

       For each test case, you should output the coordinate of C(x3,y3), the result should be rounded to 2 decimal places in a line.

 

Sample Input

4

-100.00 0.00 0.00 0.00

0.00 0.00 0.00 100.00

0.00 0.00 100.00 100.00

1.00 0.00 1.866 0.50

 

Sample Output

(-50.00,86.60)

(-86.60,50.00)

(-36.60,136.60)

(1.00,1.00)

  

 

       题意:

       给出 T,代表有 T(1 ~ 100) 个 Test。每个 Test 给出 x1,y1 ,x2,y2,(绝对值 <= 1000)代表等边三角形的其中两个点,要求输出这个等边三角形第三个点的坐标,逆时针方向。

 

       思路:

       数学。求出两个点的终点坐标 (a,b)故可以得出方程,设给出两点构成的直线斜率为 k,与该指向垂直并经过(a,b)点的直线为 k1,等边三角形边长为 d:

       r = sqrt(3) * d / 2;

       k = (y1 - y2) / (x1 - x2);

       k * k1 = -1;

       (x3 - a)^ 2 + (y3 - b)^ 2 = r ^ 2;

      (y3 - b)/ (x3 - a) = k1;

       由这些式子即可得出 x3,y3。并且对 x1 == x2 和 y1 == y2 进行另外讨论。

 

       AC:

 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

double dis(double x1, double y1, double x2, double y2) {
        double xx = (x1 - x2) * (x1 - x2);
        double yy = (y1 - y2) * (y1 - y2);
        return sqrt(3) * sqrt(xx + yy) / 2;
}

int main () {
        int t;
        scanf("%d", &t);
        while (t--) {
                double x1, y1, x2, y2;
                double d;
                scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
                d = dis(x1, y1, x2, y2);

                if (x1 == x2)
                        printf("(%.2f,%.2f)\n", x1 + (y1 > y2 ? d : -d), (y1 + y2) / 2);
                else if (y1 == y2)
                        printf("(%.2f,%.2f)\n", (x1 + x2) / 2, y1 + (x1 > x2 ? -d : d));
                else {
                        double a = (x1 + x2) / 2, b = (y1 + y2) / 2;
                        double k = (y1 - y2) / (x1 - x2);
                        double xa, xb, ya, yb;
                        xa = a + sqrt((k * k * d * d) / (1 + k * k));
                        xb = a - sqrt((k * k * d * d) / (1 + k * k));
                        ya = b - (xa - a) / k;
                        yb = b - (xb - a) / k;
                        y1 < y2 ? printf("(%.2f,%.2f)\n", xb, yb) :
                                  printf("(%.2f,%.2f)\n", xa, ya) ;
                }
        }
        return 0;
}

 

 

 

分享到:
评论

相关推荐

    mondo rescue.rar

    《Mondo Rescue在Red Hat 6.5中的应用与详解》 Mondo Rescue是一款强大的开源备份和灾难恢复工具,尤其适用于Linux系统。在本资源中,我们关注的是它在Red Hat Enterprise Linux 6.5(简称RHEL 6.5)上的应用。...

    mondo Rescue 离线包

    mond Rescue 是一款强大的开源灾难恢复工具,主要用于在Linux系统中创建完整的系统备份,包括文件系统、引导扇区、分区甚至整个硬盘。这个离线包特别适用于Red Hat Enterprise Linux 6.x(RHEL6)系统,它包含了所有...

    release of the Amsterdam Oxford Joint Rescue Force for the RoboCup Rescue Simulation Virtual Robot

    This is the code release of the Amsterdam Oxford Joint Rescue Force for the RoboCup Rescue Simulation Virtual Robot 2009 competition.

    mondo rescue3.2.1-1

    "mondo rescue3.2.1-1"是一款专为Red Hat Enterprise Linux 6.5 (RHEL 6.5) 设计的数据备份和恢复工具。Mondo Rescue 是一款开源软件,它允许用户创建完整的系统镜像,包括操作系统、应用程序、配置文件以及用户数据...

    Redhat的rescue修复模式

    ### Redhat的Rescue修复模式详解 #### 一、引言 在Redhat Linux系统中,Rescue修复模式是一种非常重要的故障恢复工具。当系统由于各种原因无法正常启动时,可以通过Rescue模式来修复系统问题,使系统恢复正常运行。...

    SQL Log Rescue

    SQL Log Rescue是一款专门用于恢复和分析SQL Server数据库中丢失数据的免费工具。它通过解析SQL Server的日志文件(也称为交易日志或T-logs),帮助用户找回由于各种原因(如误删除、意外修改或系统故障)导致的丢失...

    华硕路由固件恢复工具Rescue_2102.zip

    标题中的“华硕路由固件恢复工具Rescue_2102.zip”指的是华硕路由器的固件恢复程序,这是针对华硕路由器的一种专用软件,主要用于在固件出现问题或者需要更新时进行恢复或升级。"Rescue_2102"可能代表该工具的版本号...

    论文研究-The MANEMO Network Structure in Rescue Environment.pdf

    在分析文件“论文研究-The MANEMO Network Structure in Rescue Environment.pdf”时,我们可以从中提炼出以下知识点: ### 标题解析 - **MANEMO网络结构**:MANEMO是移动多跳自组织网络(MANET)与网络移动性...

    东南大学robocup rescue底层代码

    【东南大学RoboCup Rescue 底层代码详解】 RoboCup Rescue 是一项国际性的机器人竞赛,旨在推动灾难救援机器人的研究和发展。东南大学在该领域的参与,展现了其在人工智能、机器人技术以及应急救援算法方面的强大...

    Drive Rescue

    "Drive Rescue"就是这样一款高效的数据恢复软件,它以其强大的功能和用户友好的界面,赢得了广大用户的赞誉。 "Drive Rescue"是一款专门设计用于恢复丢失、误删除或因硬件故障导致无法访问的数据的专业工具。它具备...

    Rescue The Eggs Game using JavaScript with Source Code.zip

    《使用JavaScript制作“营救鸡蛋”游戏详解》 在当今的数字时代,JavaScript作为Web开发的主流语言之一,被广泛应用于各种网页交互和游戏开发。本教程将详细讲解如何使用JavaScript来创建一个名为“营救鸡蛋”的...

    avg rescue cd 病毒库

    AVG Rescue CD是一款强大的防病毒工具,专为在操作系统无法正常启动时进行系统恢复和病毒清除设计。这个压缩包文件包含了 AVG Rescue CD 的重要更新,特别是针对6月18日的病毒定义数据库。 AVG USB版允许用户将该...

    Rescue and Recovery 4.0 部署安装指南中文版

    ### Rescue and Recovery 4.0部署安装指南 #### Rescue and Recovery 概述 Rescue and Recovery 是联想提供的一款系统恢复工具,旨在帮助用户快速恢复计算机到出厂状态或备份时的状态,减少因系统故障而导致的数据...

    linux援救模式:linux rescue使用详细图解

    ### Linux救援模式详解:深入理解Linux Rescue的使用与实践 #### 引言 在Linux操作系统中,遇到系统崩溃、配置错误、文件系统损坏等问题时,Linux救援模式(Linux Rescue)成为了一种有效的恢复手段。本文将详细...

    Good Knight: Princess Rescue-crx插件

    语言:English,Kiswahili 一些有趣的怪兽接过你的公主并把她锁在城堡里。你需要找到8把钥匙,击败怪兽并营救他们。 一些有趣的怪物把你的公主锁在城堡里。 您需要找到8把钥匙,击败怪物并营救公主!...

    rescue server

    "Rescue Server" 是RoboCup救援仿真领域中的一个重要组成部分,主要专注于模拟灾难场景以进行机器人救援模拟比赛。RoboCup Rescue Server是一个软件平台,它为开发、测试和评估自动化救援系统提供了环境。这个平台的...

    Memory Card File Rescue.rar

    索尼(SONY)官方记忆棒数据恢复软件.数码相机记忆棒数据丢失了?就用它吧!适用于索尼(中国)有限公司在中国大陆地区销售的 Memory Stick™ 记忆棒,SD 存储卡、USB 存储器、XQD 记忆卡 和 CFast 存储卡。...

    5g.rar_5G_To The Rescue

    "5G_to_the_Rescue_Promise_Uncertainty"这个描述暗示了5G在面临巨大潜力的同时,也伴随着诸多不确定性。作为一项革命性的通信技术,5G不仅提升了网络速度,更是打开了全新的应用场景,如自动驾驶、远程医疗、智慧...

    RESCUE文件恢复

    "RESCUE文件恢复"是一款专门用于数据恢复的软件,其特点是小巧且绿色,不占用过多的系统资源,这使得它在处理文件恢复任务时既高效又便捷。在日常使用中,无论是意外删除、格式化还是硬盘损坏导致的文件丢失,这类...

    卡巴斯基杀毒启动rescue2usb.exe

    卡巴斯基 杀毒 启动 rescue2usb

Global site tag (gtag.js) - Google Analytics