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 ...
随机推荐
- 36 网络相关函数(四)——live555源码阅读(四)网络
36 网络相关函数(四)——live555源码阅读(四)网络 36 网络相关函数(四)——live555源码阅读(四)网络 简介 7)createSocket创建socket方法 8)closeSoc ...
- replace、replaceAll、replaceFirst的区别详解
String s = "my.test.txt"; System.out.println(s.replace(".", "#")); Sys ...
- MyBatis 中 Result Maps collection already contains value for xxx 错误原因
出现此类错误的原因是同一个DAO操作多个Mapper导致的,将Mapper配置文件的 ResultMap的ID修改成不相同即可解决
- 9.2---机器人走方格(CC150)
这题就是dp的一般题目 public static int countWays(int x, int y){ if( x < 0 || y < 0) return -1; int[][] ...
- 5.1---二进制数插入(CC150)
public class Solution { public static int binInsert(int n, int m, int i, int j) { // write code here ...
- 应用HTK搭建语音拨号系统2:创建单音素HMM模型
选自:http://maotong.blog.hexun.com/6204849_d.html 苏统华 哈尔滨工业大学人工智能研究室 2006年10月30日 声明:版权所有,转载请注明作者和来源 该系 ...
- NUI控件扩展
摘要:NUI组件是公司新一代的前端开发框架,它精致优雅的前端编程模型,是大家能够,或者想接受学习它的重要原因,在使用它的时候,一定不免会想增加自己的控件,让别人也能够如此优雅的使用. 其实NUI的扩展 ...
- AngularJS之Provider, Value, Constant, Service, Factory, Decorator的区别与详解
本文转载自http://camnpr.com/javascript/1693.html 首先,provider, value, constant, service, factory他们都是provid ...
- C#之文本操作
[转载]C#文件操作大全(SamWang) 文件与文件夹操作主要用到以下几个类: 1.File类: 提供用于创建.复制.删除.移动和打开文件的静态方法,并协助创建 FileStream 对象. msd ...
- 第七天 面向对象进阶与socket编程
1.静态方法(用得少)(解除某个函数跟类的关联,加了静态方法后,类便不能将类的参数传给静态方法函数了) class Dog(object): def __init__(self,name): @sta ...