山东省第四届ACM程序设计竞赛A题: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是逆时针的;
思路:
因为要求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 <bits/stdc++.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set> #define IO ios::sync_with_stdio(false);\
cin.tie();\
cout.tie(); typedef long long LL;
const long long INF = 0x3f3f3f3f;
const long long mod = 1e9+;
const double PI = acos(-1.0);
const int maxn = ;
const char week[][]= {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
const char month[][]= {"Janurary","February","March","April","May","June","July",
"August","September","October","November","December"
};
const int daym[][] = {{, , , , , , , , , , , , },
{, , , , , , , , , , , , }
};
const int dir4[][] = {{, }, {, }, {-, }, {, -}};
const int dir8[][] = {{, }, {, }, {-, }, {, -}, {, }, {-, -}, {, -}, {-, }}; 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(3.0)/+x1;
y3=dy/+dx*sqrt(3.0)/+y1;
printf("(%.2lf,%.2lf)\n",x3,y3);
}
return ;
}
山东省第四届ACM程序设计竞赛A题:Rescue The Princess的更多相关文章
- 山东省第四届ACM程序设计竞赛A题:Rescue The Princess(数学+计算几何)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 412 Solved: 168[Submit][Status][ ...
- 山东省第四届ACM程序设计竞赛部分题解
A : Rescue The Princess 题意: 给你平面上的两个点A,B,求点C使得A,B,C逆时针成等边三角形. 思路: http://www.cnblogs.com/E-star/arch ...
- UPC 2224 Boring Counting ★(山东省第四届ACM程序设计竞赛 tag:线段树)
[题意]给定一个长度为N的数列,M个询问区间[L,R]内大于等于A小于等于B的数的个数. [题目链接]http://acm.upc.edu.cn/problem.php?id=2224 省赛的时候脑抽 ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛
Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...
- 华南师大 2017 年 ACM 程序设计竞赛新生初赛题解
题解 被你们虐了千百遍的题目和 OJ 也很累的,也想要休息,所以你们别想了,行行好放过它们,我们来看题解吧... A. 诡异的计数法 Description cgy 太喜欢质数了以至于他计数也需要用质 ...
- 第13届 广东工业大学ACM程序设计大赛 C题 平分游戏
第13届 广东工业大学ACM程序设计大赛 C题 平分游戏 题目描述 转眼间又过了一年,又有一届的师兄师姐要毕业了. 有些师兄师姐就去了景驰科技实习. 在景驰,员工是他们最宝贵的财富.只有把每一个人 ...
随机推荐
- 10款好用的 jQuery 图片切换效果插件
jQuery 是一个非常优秀的 Javascript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入一些让人惊叹的效 ...
- 【AtCoder】ARC086 E - Smuggling Marbles
[题目]E - Smuggling Marbles [题意]给定n+1个点的树(root=0),每个点可以选择放或不放弹珠,每一轮顺序进行以下操作: 1.将根节点0的弹珠加入答案. 2.每个点的弹珠移 ...
- css3全屏背景显示
background:url(zhongyi2.png) no-repeat center center fixed;/* -webkit-background-size:cover; -moz-ba ...
- javaScript操作数组的常用方法
map(映射), reduce(规约), forEach(遍历), filter(过滤),它们都是高阶函数,都是以传入不同的函数来以不同的方式操作数组元.ie都不支持 判断是否为数组 Array.is ...
- Tornado/Python 学习笔记(一)
1.源代码下载及安装:http://www.tornadoweb.org/en/stable/ 2.python中xmlrpc库官方文档:https://docs.python.org/3/libra ...
- 继电器是如何成为CPU的(1)【转】
转自:http://www.cnblogs.com/bitzhuwei/p/from_relay_to_tiny_CPU.html 阅读目录(Content) 从电池.开关和继电器开始 用继电器做个与 ...
- Google Gapps – Download Gapps for Android【转】
http://wiki.rootzwiki.com/Google_Apps http://productforums.google.com/forum/#!forum/apps http://www. ...
- Swift中的指针类型
Swift编程语言为了能与Objective-C与C语言兼容,而引入了指针类型.尽管官方不建议频繁使用指针类型,但很多时候,使用指针能完成更多.更灵活的任务.比如,我们要实现一个交换两个整数值的函数的 ...
- C++ 模版的优点和缺点
优点: 1. 灵活性, 可重用性和可扩展性; 2. 可以大大减少开发时间,模板可以把用同一个算法去适用于不同类型数据,在编译时确定具体的数据类型; 3. 模版模拟多态要比C++类继承实现多态效率要高, ...
- jquery 通过 live() 方法附加的事件处理程序适用于匹配选择器的当前及未来的元素(比如由脚本创建的新元素)
jquery 通过 live() 方法附加的事件处理程序适用于匹配选择器的当前及未来的元素(比如由脚本创建的新元素) $("ul").append("<li cla ...