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. insertion sort

    1.insertion sort #include <stdio.h> #include <time.h> #include <stdlib.h> #define ...

  2. GLSL实现简单硬件Anisotrop Lighting 【转】

    http://blog.csdn.net/a3070173/archive/2008/11/13/3294660.aspx 各向异性光照往往用于处理一些具有各向异性表面的物体,如:光盘的盘面.为避免在 ...

  3. DOS命令生成文件列表

    DOS命令窗口,生成文件列表命令格式:dir xmlFiles /b >list.txt dir 文件列表相关命令 xmlFiles 待生成文件所在文件夹,在dos命令窗口根目录下,省略前缀.别 ...

  4. 升级、备份红帽PaaS openshift 上的 wordpress

    红帽提供了一个很稳定的PAAS服务平台:openshift!此博客即作为wordpress建在里面. 这里记录怎样升级与备份wordpress. 预备: 安装 openshift command li ...

  5. JS来推断文本框内容改变事件

       oninput,onpropertychange,onchange的使用方法 onchange触发事件必须满足两个条件: a)当前对象属性改变,而且是由键盘或鼠标事件激发的(脚本触发无效) b) ...

  6. Maven 插件开发(一)

    项目在重构之后,想由ant切换到maven,在转换的过程中遇到一个问题.因为项目是基于OSGi的架构,而OSGi在运行时是依赖于插件环境的,bundle之间存在package依赖.而maven是基于d ...

  7. vim替换命令

    转载:http://blog.csdn.net/glorin/article/details/6317098 替換(substitute) :[range]s/pattern/string/[c,e, ...

  8. IP101A芯片默认物理地址(PHY Adress)确定

    转载:http://blog.csdn.net/ropai/article/details/6961157 根据IP101A的DataSheet,芯片的第9,10,12,13,15脚为PHYAD0~P ...

  9. iptables常用命令

    常规: iptables -t filter -A INPUT -d -p tcp --dport -j DROPiptables -A INPUT -m iprange --src-range 22 ...

  10. 加载程序到android虚拟机报错: android.widget.RelativeLayout cannot be cast to android.widget.Button

    05-23 02:53:48.416: E/Trace(875): error opening trace file: No such file or directory (2) 05-23 02:5 ...