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 ...
随机推荐
- [转]GPS纠偏算法,适用于google,高德体系的地图
此文是转的,算法没验证过,只是记录一下. GPS纠偏算法,适用于google,高德体系的地图,精确度还比较高.我试了一下比高德本身的纠偏还精确点. /** * gps纠偏算法,适用于google,高德 ...
- 样条曲线的Fortran程序
subroutine basis_function_b_val ( tdata, tval, yval ) ! !******************************************* ...
- sqlserver 简单的事物用法
SELECT * FROM Interface_UserPort BEGIN TRY BEGIN TRAN Tran_2012_12_25 ,) --raiserror 50005N'抛出错误' CO ...
- php--递归调用
- Android笔记-获取图片
1. 图片放在sdcard中,根据路径获得: Bitmap imageBitmap = BitmapFactory.decodeFile(path) (path 是图片的路径,跟目录是/sdcard ...
- (转载)C++文件读写函数之——fopen、fread和fwrite、fgetc和fputc、fgets和fputs、ftellf和fseek、rewind
http://blog.sina.com.cn/s/blog_61437b3b0102v0bt.html http://blog.csdn.net/chenwk891/article/details/ ...
- django 部署到 apache
安装完django之后,每次都需要通过命令来启动启动开发服务器.虽然调试和测试方便,但只能在本地运行,并且不能承受许多用户同时使用的负载.所以需要将Django部署到生产级的服务器,这里选择apach ...
- 链表之求链表倒数第k个节点
题目描述:输入一个单向链表,输出该链表中倒数第k个节点,链表的倒数第0个节点为链表的尾指针. 最普遍的方法是,先统计单链表中结点的个数,然后再找到第(n-k)个结点.注意链表为空,k为0,k为1,k大 ...
- 使用C语言把字母转换成大写,不能使用库函数
char to_upper(char input) { if ('a' <= input && input <= 'z') { return input - ' ...
- iOS ASIHTTPRequest 请求https
iOS 终端请求服务端数据时,为了保证数据安全,我们一般会使用https协议加密,而对于iOS的网络编程,我们一般会使用开源框架:ASIHTTPRequest,但是如果使用传统的http方式,即使忽略 ...