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

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)

给你等边三角形的两个点A和B,求第三个点C的坐标;

且ABC是逆时针的;

题解1:

因为要求ABC是逆时针的,所以可以直接用B绕A逆时针旋转60°;

这里有个通用的公式,证明稍微复杂,可以加到模板里以备不时之需:

点(x1y1)绕点(x2y2)逆时针旋转a角度后新的坐标(XY)为:

  X=(x1-x2)*cos(a)-(y1-y2)*sin(a)+x2;

  Y=(x1-x2)*sin(a)+(y1-y2)*cos(a)+y2;

如果直接按照题意的等边三角形的情况去画图推导也可以推导出来,不过这个公式比较普适。

#include <stdio.h>
#include <iostream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
int main() {
    int t;
    scanf("%d", &t);
    while(t--){
        double x1,x2,x3,y1,y2,y3;
        scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
        double dx=x2-x1,dy=y2-y1;
        x3=dx/-dy*sqrt(+x1;
        y3=dy/+dx*sqrt(+y1;
        printf("(%.2lf,%.2lf)\n",x3,y3);
    }
    ;
}

题解2:

AB线段绕A点逆时针旋转60°后B点的位置

用到平面几何求解

x3=x1+L*cos(60°+angle);

y3=y1+L*sin(60°+angle);

angle=atan2(y2-y1,x2-x1);

#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
int main()
{
    int t;
    cin>>t;
    double  x1,y1,x2,y2,x3,y3,angle,l;
    while(t--)
    {
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        angle=atan2(y2-y1,x2-x1);
        l=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        x3=x1+l*cos(angle+PI/3.0);
        y3=y1+l*sin(angle+PI/3.0);
        printf("(%.2lf,%.2lf)\n",x3,y3);
    }
    ;
} 

Rescue The Princess的更多相关文章

  1. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  2. 山东省第四届acm.Rescue The Princess(数学推导)

    Rescue The Princess Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 412  Solved: 168 [Submit][Status ...

  3. 计算几何 2013年山东省赛 A Rescue The Princess

    题目传送门 /* 已知一向量为(x , y) 则将它旋转θ后的坐标为(x*cosθ- y * sinθ , y*cosθ + x * sinθ) 应用到本题,x变为(xb - xa), y变为(yb ...

  4. sdutoj 2603 Rescue The Princess

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...

  5. SDUT 2603:Rescue The Princess

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  6. 2013山东省“浪潮杯”省赛 A.Rescue The Princess

    A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...

  7. 山东省赛A题:Rescue The Princess

    http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3230 Description Several days ago, a beast caught ...

  8. H - Rescue the Princess ZOJ - 4097 (tarjan缩点+倍增lca)

    题目链接: H - Rescue the Princess  ZOJ - 4097 学习链接: zoj4097 Rescue the Princess无向图缩点有重边+lca - lhc..._博客园 ...

  9. 山东省第四届ACM程序设计竞赛A题:Rescue The Princess

    Description Several days ago, a beast caught a beautiful princess and the princess was put in prison ...

随机推荐

  1. 配合JAVA的AJAX使用

    概要 Ajax是“Asynchronous JavaScript and XML”的简称,即异步的JavaScript和XML. readyState属性用来返回当前的请求状态,有五个可选值.分别是0 ...

  2. 使用Kibana

    Kibana基本使用 https://www.elastic.co/guide/en/kibana/6.x/tutorial-load-dataset.html https://www.elastic ...

  3. appendTo()方法和append()方法

    appendTo() 方法在被选元素的结尾(仍然在内部)插入指定内容.

  4. vector 基础2

    size  :返回有效元素个数 max_size  :返回 vector 支持的最大元素个数 resize  :改变有效元素的个数 capacity  :返回当前可使用的最大元素内存块数(即存储容量) ...

  5. [SDOI2016] 排列计数 (组合数学)

    [SDOI2016]排列计数 题目描述 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰 ...

  6. CentOS 6.4安装配置ldap

    CentOS 6.5安装配置ldap 时间:2015-07-14 00:54来源:blog.51cto.com 作者:"ly36843运维" 博客 举报 点击:274次 一.安装l ...

  7. 获取oracle当前系统设置了哪些事件

    ALTER SESSION SET EVENTS '10046 trace name context forever,level 12' 会话已更改. DECLARE EVENT_LEVEL NUMB ...

  8. C# 序列化理解 1(转)

    序列化又称串行化,是.NET运行时环境用来支持用户定义类型的流化的机制.其目的是以某种存储形成使自定义对象持久化,或者将这种对象从一个地方传输到另一个地方.    .NET框架提供了两种串行化的方式: ...

  9. Hibernate 懒加载 错误----no session

    错误: unable to evaluate the expression Method threw 'org.hibernate.LazyInitializa org.hibernate.LazyI ...

  10. 如何根据pom.xml文件下载jar包

    遇到过这种情况:从网上下载了一个项目, 使用的maven, 但是我想要新建一个项目, 但是不需要使用maven. 但是我怎么样才能将他那个项目的所有引用的jar包给下载下载下来呢; 1.下载一个mav ...