Rescue The Princess
Description
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.
Input
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).
Output
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.
Sample Input
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
Sample Output
(-50.00,86.60) (-86.60,50.00) (-36.60,136.60) (1.00,1.00)
给你等边三角形的两个点A和B,求第三个点C的坐标;
且ABC是逆时针的;
题解1:
因为要求ABC是逆时针的,所以可以直接用B绕A逆时针旋转60°;
这里有个通用的公式,证明稍微复杂,可以加到模板里以备不时之需:
点(x1,y1)绕点(x2,y2)逆时针旋转a角度后新的坐标(X,Y)为:
X=(x1-x2)*cos(a)-(y1-y2)*sin(a)+x2;
Y=(x1-x2)*sin(a)+(y1-y2)*cos(a)+y2;
如果直接按照题意的等边三角形的情况去画图推导也可以推导出来,不过这个公式比较普适。
#include <stdio.h>
#include <iostream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while(t--){
double x1,x2,x3,y1,y2,y3;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
double dx=x2-x1,dy=y2-y1;
x3=dx/-dy*sqrt(+x1;
y3=dy/+dx*sqrt(+y1;
printf("(%.2lf,%.2lf)\n",x3,y3);
}
;
}
题解2:
AB线段绕A点逆时针旋转60°后B点的位置
用到平面几何求解
x3=x1+L*cos(60°+angle);
y3=y1+L*sin(60°+angle);
angle=atan2(y2-y1,x2-x1);
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
int main()
{
int t;
cin>>t;
double x1,y1,x2,y2,x3,y3,angle,l;
while(t--)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
angle=atan2(y2-y1,x2-x1);
l=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
x3=x1+l*cos(angle+PI/3.0);
y3=y1+l*sin(angle+PI/3.0);
printf("(%.2lf,%.2lf)\n",x3,y3);
}
;
}
Rescue The Princess的更多相关文章
- 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 ...
- sdutoj 2603 Rescue The Princess
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...
- SDUT 2603:Rescue The Princess
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- 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 ...
随机推荐
- 算法(3)Rotate Array
题目:将一个n个元素的数组右移k位,比如n=7,k=3,对数组[1,2,3,4,5,6,7]作如下旋转[5,6,7,1,2,3,4] 思路:[5,6,7,1,2,3,4],不知大家看出来了没有呢,两次 ...
- JavaScript五种继承方式详解
本文抄袭仅供学习http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 一. 构造函数绑定 ...
- 如何控制DBGrid里面显示的浮点数小数点后的位数?
现在dbgrid里面显示的位数太多,有10几位,根本没办法看.请问怎么设置能控制小数点后的位数呢?在c语言里面是 %7.2f就可以了,可惜不知道dephi里面怎么做啊谢谢各位指点 方法1: 把那些 ...
- JAXB使用方式
JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实例文档反向 ...
- hdu 1249 三角形 (递推)
三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- hdu 2527 Safe Or Unsafe (哈夫曼树)
Safe Or Unsafe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Boosting&Bagging
Boosting&Bagging 集成学习方法不是单独的一个机器学习算法,而是通过构建多个机器学习算法来达到一个强学习器.集成学习可以用来进行分类,回归,特征选取和异常点检测等.随机森林算法就 ...
- [AHOI2005]航线规划——LCT维护边双联通分量
因为只能支持加入一个边维护边双,所以时光倒流 维护好边双,每次就是提取出(x,y)的链,答案就是链长度-1 具体维护边双的话, void access(int x){ for(reg y=0;x;y= ...
- HTTP请求中同步与异步有什么不同
普通的B/S模式就是同步,而AJAX技术就是异步,当然XMLHttpReques有同步的选项. 同步:提交请求->等待服务器处理->处理完毕返回.这个期间客户端浏览器不能干任何事. 异步: ...
- Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency
E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...