计算几何 2013年山东省赛 A Rescue The Princess
/*
已知一向量为(x , y) 则将它旋转θ后的坐标为(x*cosθ- y * sinθ , y*cosθ + x * sinθ)
应用到本题,x变为(xb - xa), y变为(yb - ya)相对A点的位置,即B绕着A点旋转60度至C点
注意:计算后加回A点的坐标才是相对于原点的坐标
详细解释:http://www.tuicool.com/articles/FnEZJb
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std; const double PI = acos (-1.0); int main(void) //A Rescue The Princess
{
//freopen ("A.txt", "r", stdin); int t;
while (scanf ("%d", &t) == )
{
while (t--)
{
double xa, ya, xb, yb, xd, yd;
scanf ("%lf%lf%lf%lf", &xa, &ya, &xb, &yb);
double xc = (xb - xa) * cos (PI/3.0) - (yb - ya) * sin (PI/3.0) + xa;
double yc = (yb - ya) * cos (PI/3.0) + (xb - xa) * sin (PI/3.0) + ya;
printf ("(%.2f,%.2f)\n", xc, yc);
}
} return ;
}
/*
分各种情况讨论,这是我比赛写的,最后因为没有去绝对值而WA几次,
与上面的比较来看,可见好的思维和数学素养是多么重要:)
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std; int main(void) //A Rescue The Princess
{
//freopen ("A.txt", "r", stdin); int t;
while (scanf ("%d", &t) == )
{
while (t--)
{
double xa, ya, xb, yb, xc, yc, xd, yd;
scanf ("%lf%lf%lf%lf", &xa, &ya, &xb, &yb);
double ab = sqrt ((xa-xb) * (xa-xb) + (ya-yb) * (ya-yb));
double cd = sqrt (3.0) / * ab;
xd = (xa + xb) / ; yd = (ya + yb) / ;
if (ya == yb)
{
xc = (xa + xb) / ;
if (xa < ab)
{
yc = ya + cd;
}
else
{
yc = ya - cd;
}
}
else if (xa == xb)
{
yc = (ya + yb) / ;
if (ya > yb)
{
xc = xa + cd;
}
else
{
xc = xa - cd;
}
}
else
{
double k = (ya - yb) / (xa - xb);
k = -1.0 / k;
double q = atan (k);
//printf ("%.2f %.2f %.2f %.2f %.2f %.2f\n", ab, cd, xd, yd, k, q);
if (k > )
{
if (xa < xb)
{
xc = xd + abs (cd * cos (q));
yc = yd + abs (cd * sin (q));
}
else
{
xc = xd - abs (cd * cos (q));
yc = yd - abs (cd * sin (q));
}
}
else
{
if (xa < xb)
{
xc = xd - abs (cd * cos (q));
yc = yd + abs (cd * sin (q));
}
else
{
xc = xd + abs (cd * cos (q));
yc = yd - abs (cd * sin (q));
}
}
} printf ("(%.2f,%.2f)\n", xc, yc);
}
} return ;
}
计算几何 2013年山东省赛 A Rescue The Princess的更多相关文章
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- 2013山东省“浪潮杯”省赛 A.Rescue The Princess
A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...
- 山东省第四届acm.Rescue The Princess(数学推导)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MB Submit: 412 Solved: 168 [Submit][Status ...
- 模拟 2013年山东省赛 J Contest Print Server
题目传送门 /* 题意:每支队伍需求打印机打印n张纸,当打印纸数累计到s时,打印机崩溃,打印出当前打印的纸数,s更新为(s*x+y)%mod 累计数清空为0,重新累计 模拟简单题:关键看懂题意 注意: ...
- 位运算 2013年山东省赛 F Alice and Bob
题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- 山东省赛A题:Rescue The Princess
http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3230 Description Several days ago, a beast caught ...
- 山东省第四届ACM程序设计竞赛A题:Rescue The Princess(数学+计算几何)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 412 Solved: 168[Submit][Status][ ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
随机推荐
- Third scrum meeting - 2015/10/28
在一天的工作中明显发现到,无法和网站开发团队进行交流会严重导致我们的进程拖延,所以我们在现有的情况下也把大家的goal初步完成了,我们也对代码规范进行了详细的讨论,以及UI的设计完成,所以整个团队都真 ...
- (转)WPF控件开源资源
(转)WPF控件开源资源 Textbox Drag/Drop in WPFhttp://www.codeproject.com/Articles/42696/Textbox-Drag-Drop-in- ...
- linux下vim的常用指令
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...
- 暑假热身 E. 无聊的LSY
LSY大牛没事就爱玩游戏,包括很多很无聊的游戏.某日,LSY大牛又找到了一个无聊的游戏:每一局游戏的开始,LSY大牛将代表自己的棋子放在一个线性棋盘的最左端(第0个格子,可以认为向右端无限延伸),接着 ...
- windows下的C/C++精确计时
由于我要测试线性筛法的速度,用上了C/C++精确计时.此时传统的clock()方法不够用了,我们需要另一种测量的办法,即CPUTicks/CPUFreq.如何实现呢? #include <win ...
- Linux下crontab命令的用法
cron来源于希腊单词chronos(意为“时间”),是linux系统下一个自动执行指定任务的程序.例如,你想在每晚睡觉期间创建某些文件或文件夹的备份,就可以用cron来自动执行. 服务的启动和停止 ...
- 基础知识《零》---Java程序运行机制及运行过程
Java运行机制 Java虚拟机(Java Virtual Machine):Java虚拟机可以理解成一个以字节码为机器指令的CPU:对于不同的运行平台,有不同的虚拟机:Java虚拟机机制屏蔽了底层运 ...
- 【转】推荐一款Java反编译器,比较好用
转自:http://www.blogjava.net/xmatthew/archive/2008/10/28/237203.html 推荐一款Java反编译器,也使用了挺久的了,感觉还是很好用,就拿出 ...
- codeforces B. Sereja and Stairs 解题报告
题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...
- Java 四舍五入
http://www.cnblogs.com/xd502djj/archive/2011/07/21/2112683.html