题目传送门

 /*
已知一向量为(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. cnblog可以直接黏贴qq截图,但最好不要偷懒

    秋秋(qq)基本上算是ytkah本人开机后要开的软件了,平时也习惯用Ctrl+Alt+A快捷键来进行截图.很早以前ytkah一个无意间发现cnblog可以直接黏贴qq截图,当时截图后可能是忘记黏贴到其 ...

  2. [转]Ubuntu 系统 Update-rc.d 命令

    本文转自:http://wangyan.org/blog/ubuntu-update-rc-d.html 以防止原博客挂掉,特此做了备份. Ubuntu或者Debian系统中update-rc.d命令 ...

  3. PHP面向对象三大特点学习(充分理解抽象、封装、继承、多态)

    PHP面向对象三大特点学习 学习目标:充分理解抽象.封装.继承.多态   面象对向的三大特点:封装性.继承性.多态性 首先简单理解一下抽象:我们在前面定义一个类的时候,实际上就是把一类事物共有的属性和 ...

  4. MySQL性能优化的最佳经验

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  5. IP地址,子网掩码,默认网关

    IP地址: 是给每个连接在Internet上的主机分配的一个32bit地址. 地址有两部分组成,一部分为网络地址,另一部分为主机地址. IP地址分为A.B.C.D.E 5类.常用的是B和C两类. 网络 ...

  6. error splicing file: file too large解决方法

    FAT32格式的usb最大支持4G的文件,拷贝超过4G的文件需要把usb换成NTFS格式.

  7. mysql update case when和where之间的注意事项

    在日常开发中由于业务逻辑较为复杂,常常需要用到UPDATE和CASE...WHEN...THEN...ELSE...END一起做一些复杂的更新.有时候因为对这几个字句理解得不透彻会带来很大的困扰.因此 ...

  8. php抽象类的简单应用

    抽象类也是面向对象中的重要概念,和接口.继承的概念重要性相当,在面向对象的开发中,所有的对象都是通过类来描述的,但是反过来,并不是所有类都是用来描绘对象的,广义上讲如果一个类中没有足够信息来描述一个具 ...

  9. Java for LeetCode 199 Binary Tree Right Side View

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  10. Java跨平台原理

    此篇博文主要源自网络xiaozhen的天空的博客:http://xiaozhen1900.blog.163.com/blog/static/1741732572011325111945246/ 1.是 ...