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 ...
随机推荐
- GraphQL & Apollo & Vue
GraphQL & Apollo & Vue https://www.howtographql.com/vue-apollo/0-introduction/ https://githu ...
- 高性能服务器开发之C++定时器
高性能服务器开发之C++定时器 来源: https://www.cnblogs.com/junye/p/5836552.html 写这篇文章前搜了下网上类似的文章,有很多,所以笔者的这篇文章就不对定时 ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- 【BZOJ2663】灵魂宝石 [二分]
灵魂宝石 Time Limit: 5 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description “作为你们本体的灵魂,为了能够更好的 ...
- [bzoj1568][JSOI2008]Blue Mary开公司——李超线段树
题目大意 题解 这道题需要用到一种叫做李超线段树的东西.我对于李超线段树,是这样理解的: 给节点打下的标记不进行下传,而是仅仅在需要的时候进行下传,这就是所谓永久化标记. 对于这道题,借用一张图, 这 ...
- Linux 通过ssh传输文件
一.scp是什么? scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响 ...
- 编辑器KindEditor的使用
1.具体使用方法看点这里 2.下载点这里 3.文件夹说明 ├── asp asp示例,删掉 ├── asp.net asp.net示例,删掉 ├── attached 空文件夹,放置关联文件attac ...
- Golang在视频直播平台的高性能实践(含PPT下载)
熊猫 TV 是一家视频直播平台,先介绍下我们系统运行的环境,下面这 6 大服务只是我们几十个服务中的一部分,由于并发量与重要性比较高,所以成为 golang 小试牛刀的首批高性能高并发服务. 把大服务 ...
- python学记笔记 2 异步IO
在IO编程中,我们知道CPU的速度远远快于磁盘,网络IO,在一个线程中,CPU执行速度的代码非常快,然而遇到IO操作就需要阻塞 需要等待IO操作完成才能继续下一步的动作.这种情况叫做同步IO 在IO操 ...
- Ubuntu Touch环境搭建
最近搞了一下Nexus 5的MultiRom Manger,体验了一把Ubuntu Touch和Android L,总体感觉还不错,不过Android L的NFC驱动还有问题,Ubuntu Touch ...