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. file_get_contents无法获取数据的一种情况

    下面这段php代码突然不好使了,返回的 $html 为空,百思不得解.网上说法好多,但都是一家之言,解决不了我的问题.(我的解决方法也是一家之言,只能解决file_get_contents获取不到数据 ...

  2. 【php学习】字符串操作

    关于字符串的处理,基本上就是那几种操作:字符串长度.查找子字符串的位置.替换字符串.截取字符串.拆分合并字符串 ... 字符串的定义:直接 $str = "abcd"; 或者 $s ...

  3. X Window 程式设计

    X Window 程式设计 转   http://www.cppblog.com/zmj/archive/2007/05/18/24331.html X Window 程式设计 X Window 程式 ...

  4. 实验 snort安装配置与规则编写

    1 实验目的 在linux或windows任意一个平台下完成snort的安装,使snort工作在NIDS模式下,并编写符合相关情景要求的snort规则. 2 实验环境 物理机:windows 8.1 ...

  5. 关于Xib 需要注意的地方

    当你需要写一个繁琐的界面但是又是静态页面时,很可能会用到xib [特例:创建继承于UIView的文件时,不带自动生成xib的勾选项,需要开发人员手动new一个同名的xib文件,在该xib文件右侧的cl ...

  6. recordcount

    rs.recordcount 有时不能取到数,这时 要更改游标为客户端游标 .

  7. JS-007-富文本域操作

    在日常 web 编写过程中,富文本域几乎成为了一个网站不可页面元素,同时,其也有着各种各样的实现方式,网络上也存在着各种各样的集成插件可供引用.此文以 js 获取.修改 163 邮箱写邮件时的邮件内容 ...

  8. qt QMessageBox QInputDialog

    最近用到了QMessgaeBox和QInputDialog,QMessageBox用于提示,警告等消息,QInputDialog给用户弹出输入对话框. 参考链接 http://chenboqiang. ...

  9. VS2013搭建wxWidgets开发环境

    一.安装 前往官网下载最新wxWidgets 3.0.0. https://sourceforge.net/projects/wxwindows/files/3.0.0/wxMSW-3.0.0-Set ...

  10. 移动端省际联动插件mobiscroll

    <link href="assets/css/mobiscroll.custom-2.17.0.min.css" rel="stylesheet" typ ...