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. 利用FFT来进行字符串匹配

    给定串A和串B,A由26个小写字母构成,B由?和26个小写字母构成 ?可以和任意字符匹配 求A中出现了多少次B 这里可以使用fft做法,定义向量A和向量B 然后求A和rev(B)的卷积结果C C的第i ...

  2. JS Cookie相关操作

    function setCookie(cookieName, cookieValue, expires) { // 设置Cookie function getCookieName(cookieName ...

  3. [SDOI2011]消防/[NOIP2007] 树网的核

    消防 题目描述 某个国家有n个城市,这n个城市中任意两个都连通且有唯一一条路径,每条连通两个城市的道路的长度为zi(zi<=1000). 这个国家的人对火焰有超越宇宙的热情,所以这个国家最兴旺的 ...

  4. js获取当前url地址参数中文乱码问题

    网上看了一些关于此问题的文章,都说的不清不楚,有些更是乱七八糟,完全没法看,故此找了一篇能用的,借鉴作为笔记. //首先获取到当前页面的地址栏信息 var url = window.location. ...

  5. Lucene4.6查询时完全跳过打分,提高查询效率的实现方式

    由于索引的文件量比较大,而且应用中不需要对文档进行打分,只需要查询出所有满足条件的文档.所以需要跳过打分来提高查询效率.一开始想用ConstantScoreQuery,但是测试发现这个类虽然让所有返回 ...

  6. python中orm框架学习

    安装sqlalchemy pip3 install sqlalchemy 创建表结构: from sqlalchemy import Column,String,create_engine from ...

  7. CDQ 学习笔记

    CDQ分治 CDQ(陈丹琦)分治是一种特殊的分治方法. 它只能处理非强制在线的问题. CDQ分治在维护一些动态的凸包.半平面交问题也有一定应用,然而本渣渣并不会. CDQ分治基于时间分治,整体二分基于 ...

  8. bzoj 1303 杂题

    首先如果一个数是中位数,在这段区间中比他大的数量=比他小的数量,那么如果一个数比他大设为1,比他小设为-1,设要求的数在数组中的位置是mid,那么我们可以用num[i] 表示1-mid这一段中,j-m ...

  9. PHP HERE DOCUMENT

    转自: http://www.codeweblog.com/php%E4%B8%ADheredoc%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/ Here ...

  10. [Leetcode Week5]Word Ladder

    Word Ladder题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder/description/ Description Give ...