题目传送门

 /*
已知一向量为(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的更多相关文章

  1. 2013年山东省赛F题 Mountain Subsequences

    2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...

  2. 2013山东省“浪潮杯”省赛 A.Rescue The Princess

    A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...

  3. 山东省第四届acm.Rescue The Princess(数学推导)

    Rescue The Princess Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 412  Solved: 168 [Submit][Status ...

  4. 模拟 2013年山东省赛 J Contest Print Server

    题目传送门 /* 题意:每支队伍需求打印机打印n张纸,当打印纸数累计到s时,打印机崩溃,打印出当前打印的纸数,s更新为(s*x+y)%mod 累计数清空为0,重新累计 模拟简单题:关键看懂题意 注意: ...

  5. 位运算 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 ...

  6. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  7. 山东省赛A题:Rescue The Princess

    http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3230 Description Several days ago, a beast caught ...

  8. 山东省第四届ACM程序设计竞赛A题:Rescue The Princess(数学+计算几何)

    Rescue The Princess Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 412  Solved: 168[Submit][Status][ ...

  9. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

随机推荐

  1. Protocol Buffers介绍

    基本概念 Protocol Buffers(以下简称PB)是一种独立于语言.独立于开发平台.可扩展的序列化数据结构框架,它常常被用在通信.数据序列化保存等方面. PB是一种敏捷.高效.自动化的用于对数 ...

  2. 自定义 array_map() 对应的递归函数 array_map_recursive()

    array_walk 有个原生递归函数 array_walk_recursive($arr, 'function', 'words'),但是 array_map 却没有对应的递归函数 array_ma ...

  3. L17 怎么向应用程序商店提交应用

    原地址:https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/ApplicationD ...

  4. storyboard和xib的各种问题

    1.prepareFoSegue注意问题使用该方法设置的值, 必须要 viewWillApear之后用 2.storayboard的使用autolayout, constant = -16, 刚好在f ...

  5. Git SSH Key 生成步骤

    it是分布式的代码管理工具,远程的代码管理是基于ssh的,所以要使用远程的git则需要ssh的配置. github的ssh配置如下: 一 . 设置git的user name和email: $ git ...

  6. Power of Two & Power of Three & Power of Four

     Check Power of 2 Using O(1) time to check whether an integer n is a power of 2. Example For n=4, re ...

  7. TestPointer

     C++ Code  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...

  8. win10远程桌面连接

    有的情况下,Win10设置了允许远程桌面连接后,远程主机仍然不能桌面连接到目标主机上,这时可以在目标主机上尝试如下修改: 开始-->运行->gpedit.msc->计算机配置-> ...

  9. Java for LeetCode 076 Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  10. Java for LeetCode 025 Reverse Nodes in k-Group

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...