Rescue The Princess (数学水题)

Rescue The Princess

 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 equilateral triangle 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?


  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.

输出

    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.

示例输入

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

示例输出

(-50.00,86.60)
(-86.60,50.00)
(-36.60,136.60)
(1.00,1.00)

就是给出a,b的坐标求等边三角形c点的坐标;
代码“:
#include <stdio.h>
#include<math.h>
#define l sqrt(3)
int main()
{
    double xa,ya,xb,yb,x0,y0;
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf%lf%lf",&xa,&ya,&xb,&yb);
            x0=(xa+xb)/2;
            y0=(ya+yb)/2;
            if(xa==xb)
                printf("(%.2lf,%.2lf)\n",xa+l*(ya-yb)/2,y0);
            else if(ya==yb)
                printf("(%.2lf,%.2lf)\n",x0,ya+l*(xb-xa)/2);
            else
            {
                double kb,k0,xf,yf;
                k0=-(xb-xa)/(yb-ya);
                kb=(k0+l/3)/(1-k0*l/3);
                xf=(yb-y0+k0*x0-kb*xb)/(k0-kb);
                yf=((xa-xb)/2+yb/kb-y0/k0)/(1/kb-1/k0);
                printf("(%.2lf,%.2lf)\n",xf,yf);
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ansible Rescue是一种用于处理故障和恢复的方法。可以使用Ansible Rescue来重新安装操作系统、修复配置文件、恢复数据等。在Ansible中,可以通过编写一个playbook来定义Rescue任务,该playbook包含了需要执行的一系列任务。在执行Rescue任务时,Ansible会评估任务的返回代码,以确定任务是成功还是失败。当任务失败时,Ansible会立即中止play的其余部分,并跳过所有后续任务。此外,还可以使用Ansible的fail模块来强制任务失败,以便进行特定的处理。例如,可以编写一个任务来运行用户创建脚本,并在脚本输出中检查是否缺少密码,如果缺少密码,则使用fail模块报告脚本失败。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [install-arch-linux-server:提供一个命令,通过运行的 Ubuntu live 在服务器上格式化和安装 arch linux](https://download.csdn.net/download/weixin_42157567/19894698)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [ansible实施处理程序和处理失败任务](https://blog.csdn.net/weixin_58130165/article/details/119143078)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值