sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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?
输入
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.
输出
示例输入
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
示例输出
(-50.00,86.60)
(-86.60,50.00)
(-36.60,136.60)
(1.00,1.00)
提示
来源
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
#define eps 1e-10
#define PI acos(-1)
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vector ;
Vector operator + (Vector a,Vector b)
{
return Vector(a.x+b.x,a.y+b.y);
}
Vector operator - (Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
Vector operator * (Vector a,double b)
{
return Vector(a.x*b,a.y*b);
}
Vector operator / (Vector a,double b)
{
return Vector(a.x/b,a.y/b);
}
double Cross(Vector a,Vector b)
{
return a.x*b.y-b.x*a.y;
}
Vector Rotate(Vector A,double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
Vector u = P-Q;
double t = Cross(w,u) / Cross(v,w);
return P+v*t;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
Point a,b;
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
Point c = GetLineIntersection(a,Rotate(b-a,PI/),b,Rotate(b-a,PI*/));
printf("(%.2lf,%.2lf)\n",c.x,c.y);
}
return ;
} /**************************************
Problem id : SDUT OJ 2603
User name : Miracle
Result : Accepted
Take Memory : 512K
Take Time : 0MS
Submit Time : 2014-05-04 09:16:11
**************************************/
Freecode : www.cnblogs.com/yym2013
sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)的更多相关文章
- sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)
Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you a ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
Pixel density Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Pixels per inch (PPI) or pi ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- SDUT 2603:Rescue The Princess
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)
n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you w ...
- sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
随机推荐
- bug-android之INSTALL_FAILED_NO_MATCHING_ABIS
bug描述: 经常在网络上下载一些实例,自己研究 ,运行时不时会出现这个bug: Installation error: INSTALL_FAILED_NO_MATCHING_ABIS bug解决方案 ...
- ModelAndView的介绍
ModelAndView的构造方法有7个.但是它们都是相通的.这里使用无参构造函数来举例说明如何构造ModelAndView实例. ModelAndView类别就如其名称所示,是代表了MVC Web程 ...
- 转:JQuery实现下拉框的数据加载和联动
<script type="text/javascript"> $(document).ready(function() { GetByJquery(); $(&quo ...
- rpm包制作(待实验)
作者:firefoxbug 时间:July 18, 2014 rpm包命名规范 对于rpm包的命名符合如下规范. %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm N ...
- openstacksdk enable logging
http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/doc/source/users/guides/logging.rst
- 数据库Error:The ScriptCollection in ScriptName not find
System.InvalidOperationException: The ScriptCollection in ScriptName not find 在 WMI.SQL.HELPER.CONFI ...
- float 在内存中如何存储的
float类型数字在计算机中用4个字节存储.遵循IEEE-754格式标准: 一个浮点数有2部分组成:底数m和指数e 底数部分 使用二进制数来表示此浮点数的实际值指数部分 占用8bit的二进制数, ...
- 开始学习C++
这里突然想起来当初学习java和C# 总是会有个demo : hello world. 这里我记得我曾经看过一个笑话.说有个程序员,想学习书法,买了笔墨,都准备好了,但是不知道写什么好.最后,他大 ...
- pfsense 企业应用实例
从萌生更换公司网关的想法,到选择.测试.部署陆陆续续用时两个月有余.选择的标准是open and free.这期间不断在查阅一些资料,测试了7.8个各开源防火墙产品.这些产品中大多是基于linux,少 ...
- progressBar走马灯设置
初始值Visible = false; 让progressBar1出现时: progressBar1.Visible = true; progressBar1.Style = ProgressBarS ...