A.Rescue The PrincessDescription

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)

最原始方法是算算算,在别人博客学到的是用旋转矩阵的,感觉厉害多了..

例如:把向量写成坐标形式并视为一个2*1列向量,再左乘一个2*2的矩阵,这样得到的新的2*1列向量就是旋转后的向量的坐标。(2*2矩阵结构如下:设旋转 角度为a, 那么左上角和右下角的元素为cos(a), 右上角的元素为-sin(a), 左下角的元素为sin(a))。

#include<cstdio>
#include<cstring>
#include<cmath>
const double sq3=sqrt(3.0);
double m1[][],m3[][];
double m2[][]= {{0.5,sq3/},{-sq3/,0.5}};
void so()
{
memset(m3,,sizeof(m3));
for(int k=; k<; ++k)
for(int j=; j<=; ++j)
{
//printf("m1[0][%d]=%lf m2[%d][%d]=%lf\n",k,m1[0][k],k,j,m2[k][j]);
m3[][j]+=m1[][k]*m2[k][j];
} }
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double x1,x2,y1,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
m1[][]=x2-x1;
m1[][]=y2-y1;
so();
printf("(%.2lf,%.2lf)\n",m3[][]+x1,m3[][]+y1);
}
return ;
}

2013山东省“浪潮杯”省赛 A.Rescue The Princess的更多相关文章

  1. [ACM]2013山东省“浪潮杯”省赛 解题报告

    题目地址:http://acm.upc.edu.cn/problemset.php?page=13  2217~2226 A.Rescue The Princess 一个等边三角形告诉前2个点,求逆时 ...

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

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

  3. 2014山东省“浪潮杯”第五届ACM省赛总结

    一次比赛做一次总结,弱菜又来总结了…… 我这种大四的又死皮赖来混省赛了,貌似就我和山大威海的某哥们(不详其大名)了吧.颁奖前和他聊天,得知他去百度了,真是不错,ORZ之. 比赛流水账: 题目目前不知道 ...

  4. Anagram(山东省2018年ACM浪潮杯省赛)

    Problem Description Orz has two strings of the same length: A and B. Now she wants to transform A in ...

  5. 2013年蓝桥杯省赛C/C++A组真题解析

    1.高斯日记 大数学家高斯有个好习惯:无论如何都要记日记. 他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210 后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的 ...

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

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

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

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

  8. Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)

    题目描述 Cainiao is a university student who loves ACM contest very much. It is a festival for him once ...

  9. [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛

    本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...

随机推荐

  1. 用C#.NET实现电子邮件客户程序

    用C#.NET实现电子邮件客户程序 周华清 戴晟辉(东华理工学院计算机与通信系 江西 抚州 344000) [摘要]通过C#这种VisualSTudio.NET中新引入的面向对象且类型安全的编程语言, ...

  2. Ubuntu下多服务器 Rsync同步镜像服务配置

    主服务器:192.168.5.13_ubuntu 从服务器:192.168.5.11_centos ================== 1> 在两台主机上分别安装rsync========== ...

  3. STL 案例分析

    #include <iostream> using namespace std; #include "string" #include <vector> # ...

  4. Spark Streaming metadata checkpoint

    Checkpointing 一个流应用程序必须全天候运行,所有必须能够解决应用程序逻辑无关的故障(如系统错误,JVM崩溃等).为了使这成为可能,Spark Streaming需要checkpoint足 ...

  5. C#开发---利用特性自定义数据导出到Excel

    网上C#导出Excel的方法有很多.但用来用去感觉不够自动化.于是花了点时间,利用特性做了个比较通用的导出方法.只需要根据实体类,自动导出想要的数据  1.在NuGet上安装Aspose.Cells或 ...

  6. C语言bool类型定义

    在我们的C语言程序中,经常用到布尔类型,但是C标准并不支持布尔类型,但我们可以自己实现其类型,实现代码如下:typedef enum{ false = 0, ture = !false}bool;

  7. 使用JS制作一个鼠标可拖的DIV(一)——鼠标拖动

    使用 JS 来实现一个可拖动的DIV,主要是使用到以下几个事件: 1.鼠标按下:DIV元素的onmousedown. 2.鼠标按住拖动:document 的 onmousemove 元素. 3.鼠标放 ...

  8. CSS: Float a div on another div, Ex: Text caption on picture

    <style type="text/css"> .figure { width: 316px; height: 205px; display: block; borde ...

  9. OPENSSL安装 以及使用openssl中的AES加密和解密

    OPENSSL安装:(VS) 1:第一步和所有的软件安装一样. 2:将OPENSSL中INLUCDE 和 LIB 分别拷贝到VS中VC的INLUCDE 和LIB目录下(我的机器上的目录是:C:\Pro ...

  10. xml版本学生管理系统

    一: 需求描述 学生成绩管理系统,使用xml存储学生信息,可以对学生信息进行增.删.删除操作. 主要目的:练习操作xml元素的增删改查 二:代码结构 1:xml存储数据如下 exam.xml < ...