计算几何 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 ...
随机推荐
- [Effective JavaScript 笔记] 第7条:视字符串为16位的代码单元序列
Unicode编码,基础:它为世界上所有的文字系统的每个字符单位分配一个唯一的整数,该整数介于0~1114111之间,在Unicode术语中称为代码点(code point). 和其它字符编码几乎没有 ...
- Unity运行时刻资源管理
原地址:http://www.cnblogs.com/88999660/archive/2013/04/03/2998157.html Unity运行时刻资源管理 ------------------ ...
- [BZOJ3872][Poi2014]Ant colony
[BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...
- MYSQL注入天书之HTTP头部介绍
Background-5 HTTP头部介绍 在利用抓包工具进行抓包的时候,我们能看到很多的项,下面详细讲解每一项. HTTP头部详解 1. Accept:告诉WEB服务器自己接受什么介质类型,*/* ...
- PCA
理论部分可以看斯坦福大学的那份讲义,通俗易懂:http://www.cnblogs.com/jerrylead/archive/2011/04/18/2020209.html opencv中有PCA这 ...
- ZeroMQ之Request/Response (Java)
自己最开始是在cloud foundry中接触过消息服务器(nats),或者说是消息中间件,也算是初步知道了一个消息服务器对于分布式的网络系统的重要性,后来自己也曾想过在一些项目中使用它,尤其是在一些 ...
- (转)女生应该找一个玩ACM的男生
1.强烈的事业心 将来,他也一定会有自己热爱的事业.而且,男人最性感的时刻之一,就是他专心致志做事的时候.所以,找一个机会在他全神贯注玩ACM的时候,从侧面好好观察他,你就会发现我说的话没错. 2.永 ...
- 【OpenStack】OpenStack系列1之Python虚拟环境搭建
安装virtualenv相关软件包 安装:yum install python-virtualenv* -y 简介,安装包主要包括, python-virtualenv:virtualenv用于创建独 ...
- 51nod 1264 线段相交
题目:传送门. 题意:给两条线段,有一个公共点或有部分重合认为相交,问他们是否相交. 题解:这属于非规范相交的情况,模板题. #include <iostream> #include &l ...
- [Android Pro] 监听Blutooth打开广播
<uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission a ...