sdutoj 2603 Rescue The Princess
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.
输出
示例输入
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 <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的更多相关文章
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- SDUT 2603:Rescue The Princess
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- 山东省第四届acm.Rescue The Princess(数学推导)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MB Submit: 412 Solved: 168 [Submit][Status ...
- 计算几何 2013年山东省赛 A Rescue The Princess
题目传送门 /* 已知一向量为(x , y) 则将它旋转θ后的坐标为(x*cosθ- y * sinθ , y*cosθ + x * sinθ) 应用到本题,x变为(xb - xa), y变为(yb ...
- 2013山东省“浪潮杯”省赛 A.Rescue The Princess
A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...
- 山东省赛A题:Rescue The Princess
http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3230 Description Several days ago, a beast caught ...
- H - Rescue the Princess ZOJ - 4097 (tarjan缩点+倍增lca)
题目链接: H - Rescue the Princess ZOJ - 4097 学习链接: zoj4097 Rescue the Princess无向图缩点有重边+lca - lhc..._博客园 ...
- 山东省第四届ACM程序设计竞赛A题:Rescue The Princess
Description Several days ago, a beast caught a beautiful princess and the princess was put in prison ...
- Rescue The Princess
Description Several days ago, a beast caught a beautiful princess and the princess was put in prison ...
随机推荐
- php安装,mysql安装
先安装mysql 下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads 选择“Source Code”,用已经注册好的oracle账 ...
- 【转】C# 解析JSON格式数据
http://blog.csdn.net/coolszy/article/details/8606803 JSON简介 JSON(全称为JavaScript ObjectNotation) 是一种轻量 ...
- 关于使用注解出现BeanCreationException或者NameNotFoundException的解决方法
网上大部分解决方法是修改配置文件,但是本人修改后发现还是报错,只能耐着头皮继续看下去,最后发现是path出错,注意web.xml中的<resource-ref>的<res-ref-n ...
- Solr4.3之拼写检查Spellcheck功能
原文地址:http://www.656463.com/article/iaquii.htm 拼写检查功能,能在搜索时提供一个较好用户体验,所以,主流的搜索引擎都有这个功能,在这之前,笔者先简单的说一下 ...
- jsp 标签、 项目全路径引用${CTX}
请根据自己的需要选择以下标签. <%@ taglib uri="/struts-tags" prefix="s"%><%@ taglib ur ...
- PySe-002-Py-简单示例及编码设定
非常简单而又国际化的例子 Hello World!在控制台依次输入命令:python, print "This is first program %s" % "Hello ...
- synchronized原理
http://www.cnblogs.com/YDDMAX/p/5658607.html http://www.cnblogs.com/YDDMAX/p/5658668.html synzhroniz ...
- json和string 之间的相互转换
json和string 之间的相互转换 <script type="text/javascript"> //先认识一下js中json function showInfo ...
- CentOS6.5Minimal安装Gitlab7.5
文章出处:http://www.restran.net/2015/04/09/gilab-centos-installation-note/ 在 CentOS 6.5 Minimal 系统环境下,用源 ...
- Bash中的shopt选项
Bash中的shopt选项 http://blog.chinaunix.net/uid-20587169-id-1919110.html shopt命令用于显示和设置shell中的行为选项,通过这些选 ...