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. Android Developers:在命令行构建和运行

    使用Ant构建脚本构建你的应用程序有两种方式:一种用于测试/调试你的引用程序—debug模式—另一种用于构建你最终发布的包-release模式.无论你使用哪种方式构建你的应用程序,它必须在安装在模拟器 ...

  2. WPF基础到企业应用系列7——深入剖析依赖属性(WPF/Silverlight核心)

    一. 摘要 首先圣殿骑士非常高兴这个系列能得到大家的关注和支持.这个系列从七月份開始到如今才第七篇,上一篇公布是在8月2日,掐指一算有二十多天没有继续更新了,最主要原因一来是想把它写好,二来是由于近期 ...

  3. delphi 设置超链接

     的属性 的事件 的方法 //1设置链接类型//2获取样式 链接和提示信息 //title是提示信息//HTTPS https://<a href="https://www.baidu ...

  4. JellyViewPager

    https://github.com/jfeinstein10/JazzyViewPager https://github.com/chiemy/JellyViewPager JellyViewPag ...

  5. C++之运算符重载(1)

    在前一节中曾提到过,C++中运行时的多态性主要是通过虚函数来实现的,而编译时的多态性是由函数重载和运算符重载来实现的.这一系列我将主要讲解C++中有关运算符重载方面的内容.在每一个系列讲解之前,都会有 ...

  6. yar

    <?php class Operator { /** * 两数相加 */ public function add($a, $b) { return $this->_add($a, $b); ...

  7. [Java] 集合类(List、Set、Map的基本使用)

    数组是一种很常见的数据结构,开始接触编程的时候多数程序都和数组相关.刚开始接触Java时也是一直使用数组写一些程序,后来越来越觉得... 数组是一种很常见的数据结构,开始接触编程的时候多数程序都和数组 ...

  8. Android(java)学习笔记106-1:深入分析Java ClassLoader原理

    1. 前言: Android中的动态加载机制能更好的优化我们的应用,同时实现动态的更新,这就便于我们管理我们的应用,通过插件化来减轻我们的内存以及CPU消耗,在不发布新版本的情况下能更新某些模块. 当 ...

  9. [置顶] 《MFC游戏开发》笔记一 系列简介

    本系列文章由七十一雾央编写,转载请注明出处.  http://blog.csdn.net/u011371356/article/details/9299121 作者:七十一雾央 新浪微博:http:/ ...

  10. Shell学习笔记 - 运算符

    一.Declare命令 1. 命令格式 declare [+/-] [选项] 变量名 其中: -: 给变量设定类型属性 +:取消变量的类型属性 2. 参数说明 -i:将变量声明为整型 -a:将变量声明 ...