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. osg 笔记一 (转)

    场景图形采用一种自顶向下的,分层的树状数据结构来组织空间数据集,以提高渲染的效率 场景图形树结构的顶部是一个根节点,从根节点向下延伸,各个组节点中均包含了几何信息和用于控制其外观的渲染状态信息.根节点 ...

  2. 设置Delphi XE4默认界面样式

    VCL BitMap Style   Proceject Options->Application->Appearance 选择几个样式 使用代码设置   uses Vcl.Themes; ...

  3. 【Bootstrap3.0建站笔记三】AspNetPager分页,每一列都可排序

    1.AspNetPager分页,实现每一列都可排序:           (1).须要将默认排序字段放在HTML页面中.           (2).排序字段放置为td节点的属性. 如图: 实现的效果 ...

  4. MaterialDesignLibrary

    https://github.com/navasmdc/MaterialDesignLibrary MaterialDesignLibrary.zip

  5. 项目中oracle存储过程记录——经常使用语法备忘

    项目中oracle存储过程记录--经常使用语法备忘 项目中须要写一个oracle存储过程,需求是收集一个复杂查询的内容(涉及到多张表),然后把符合条件的记录插入到目标表中.当中原表之中的一个的日期字段 ...

  6. 图解JS原型链

    一:任何一个对象都有一个prototype的属性,在js中可以把它记为:__proto__ 当初ECMAscript的发明者为了简化这门语言,同时又保持继承的属性,于是就设计了这个链表.. 在数据结构 ...

  7. Ubuntu开机时出现&quot;没有正确安装GNOME电源管理器的默认配置

    1:在登录界面.按Ctrl+Alt+F1,进入控制台命令行模式 2:先输入username,回车,然后输入password,登录成功 3:输入df -h,这个命令是查看硬盘空间的.能够看一下.你的ho ...

  8. php中数组自定义排序

    php中数组自定义排序方法有很多,现在只提usort();不会保留原有键名. unsort调用方法就是unsrot($arr,func); 注意: 如果func是写在当前类中的话,那么调用的方式是 u ...

  9. MYSQL SQL 审核工具 (inception安装步骤)

    http://blog.csdn.net/wulantian/article/category/5825391

  10. Android基本控件之Menus

    在我们的手机中有很多样式的菜单,比如:我们的短信界面,每条短信,我们长按都会出现一个菜单,还有很多的种类.那么现在,我们就来详细的讨论一下安卓中的菜单 Android的控件中就有这么一个,叫做Menu ...