http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603

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.

输出

    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.

示例输入

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)

提示

 

来源

2013年山东省第四届ACM大学生程序设计竞赛

示例程序

分析:

已知等边三角形的两个按逆时针给出的两个顶点,求第三个点。

官方代码:

 #include <stdio.h>
#include <math.h>
const double pi = acos(-1.0);
int main()
{
int t;
double x1,x2,x3,y1,y2,y3,l,at;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
at = atan2(y2-y1,x2-x1);
printf("%lf\n",(y2-y1)/(x2-x1));
printf("%lf\n",at);
l = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
x3 = x1+l*cos(at+pi/3.0);
y3 = y1+l*sin(at+pi/3.0);
printf("(%.2lf,%.2lf)\n",x3,y3);
} return ;
}

AC代码:

 #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define D double
#define PI acos(-1.0)
D x3,y3;
int d1, d2;
D Length(D x1,D y1,D x2,D y2 )
{
return sqrt((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1));
}
void Solve(D x1, D y1, D x2,D y2)
{
D Radian = atan((y2 - y1)/(x2 - x1));
D Angle = Radian * 180.0 / PI;
if (x1 > x2)
Angle += 180.0;
Radian += PI/3.0;
Angle += 60.0;
if (Angle <= || Angle >= )
d1 = ;
else
d1 = -;
if (Angle >= && Angle <= )
d2 = ;
else
d2 = -;
D dis = Length(x1,y1,x2,y2);
x3 = x1 + d1 * dis * fabs(cos(Radian));
y3 = y1 + d2 * dis * fabs(sin(Radian));
}
int main()
{
int T;
D x1, y1, x2, y2;
scanf ("%d", &T);
while (T --)
{
scanf ("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
Solve(x1, y1, x2, y2);
printf ("(%.2lf,%.2lf)\n", x3, y3);
} return ;
}

还可以推出公式的:

利用向量的旋转:http://www.cnblogs.com/jeff-wgc/p/4468038.html

AC代码:

 #include<stdio.h>
#include<math.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double x1,x2,y1,y2,x3,y3,x,y;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
x=x2-x1;
y=y2-y1;
x3=x/-y*sqrt()/+x1;
y3=y/+x*sqrt()/+y1;
printf("(%.2f,%.2f)\n",x3,y3);
}
return ;
}

sdutoj 2603 Rescue The Princess的更多相关文章

  1. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  2. SDUT 2603:Rescue The Princess

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  3. 山东省第四届acm.Rescue The Princess(数学推导)

    Rescue The Princess Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 412  Solved: 168 [Submit][Status ...

  4. 计算几何 2013年山东省赛 A Rescue The Princess

    题目传送门 /* 已知一向量为(x , y) 则将它旋转θ后的坐标为(x*cosθ- y * sinθ , y*cosθ + x * sinθ) 应用到本题,x变为(xb - xa), y变为(yb ...

  5. 2013山东省“浪潮杯”省赛 A.Rescue The Princess

    A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...

  6. 山东省赛A题:Rescue The Princess

    http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3230 Description Several days ago, a beast caught ...

  7. H - Rescue the Princess ZOJ - 4097 (tarjan缩点+倍增lca)

    题目链接: H - Rescue the Princess  ZOJ - 4097 学习链接: zoj4097 Rescue the Princess无向图缩点有重边+lca - lhc..._博客园 ...

  8. 山东省第四届ACM程序设计竞赛A题:Rescue The Princess

    Description Several days ago, a beast caught a beautiful princess and the princess was put in prison ...

  9. Rescue The Princess

    Description Several days ago, a beast caught a beautiful princess and the princess was put in prison ...

随机推荐

  1. Java中共享设计

    Java中的共享设计的思路是在Java中形成一个对象池,在这个对象池中保存多个对象, 新实例化的对象如果已经在池中定义了,则不再重复新定义,而从池中直接取出继续使用. 例如,对于字符串来说,Java ...

  2. (转)Linux下安装Matlab2014及破解

    原文链接:http://blog.csdn.net/lanbing510/article/details/41698285 文章已搬家至http://lanbing510.info/2014/12/0 ...

  3. 浮动以后父DIV包不住子DIV解决方案

    转载自http://blog.sina.com.cn/s/blog_6c363acf0100v4cz.html 当DIV1里面嵌套有一个DIV2,当DIV2设置了浮动,那么DIV1是无法被撑开的,也就 ...

  4. spring-3-mvc-hello-world-example

    http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/

  5. composer 272解决

    composer global require "fxp/composer-asset-plugin:~1.0.3"                                 ...

  6. 蓝牙BLE 架构剖析

    一.BLE架构概述: 二.各个层

  7. C/C++ 判断主机字节存储序列

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0oAAADFCAIAAADltpUqAAAgAElEQVR4nOyd65XyvA6FqYASKIEWqI

  8. fprintf与fwrite函数用法与差异

    在C语言中有两个常见的保存文件的函数:fprintf 与 fwrite.其主要用法与差异归纳如下: 一.fprintf函数. 1.以文本的形式保存文件.函数原型为 int fprintf(FILE* ...

  9. dedecms程序给栏目增加缩略图的方法

    用织梦程序做网站,有时候因为功能需求,我们要为网站的栏目页添加缩略图功能,而dedecms又没自带这个功能,那么就需要我们来修改程序了. 这里有一个栏目添加缩略图的方法,供大家参考. 涉及到文件如下( ...

  10. [RVM is not a function] Interating RVM with gnome-terminal

    Ubuntu 12.04 64bit LTS, running the 'rvm use 1.9.3' brings the 'RVM is not a function' warning. Here ...