hdu4998 旋转坐标系
题意:
一开始的时候有一个坐标系(正常的),然后有n个操作,每个操作是 x y d,意思是当前坐标系围绕x,y点逆时针旋转d度,最后让你输出三个数x y d,把这n个操作的最后结果,用一步等效过来,就是找到一个点,逆时针旋转一个度数,等于当前的这个状态。
思路:
我们可以用一个向量来代表当前坐标系,每次操作把当前向量拆成两个点单独操作,假如当前向量a,b,绕点c旋转d度,那么我们可以等效向量c,a逆时针旋转d,然后向量c,b逆时针旋转d,这样就的到了两个新的向量,此时我们要根据这两个新的向量求出当前这两个点的新位置,然后再用当前的新位置和下一组操作,最后得到了最终的一个向量,现在我们只要求出初始向量和最终向量的转换关系就行了,这个地方首先我们求转换点,求法是两个向量的x,x'连线,y.y'连线,两条线段中垂线的交点,求出交点之后再用余弦定理求出夹角,然后在用向量的关系来判断要不要用2PI-当前度数,具体看代码。
#include<math.h>
#include<algorithm>
#include<stdio.h>
#define maxn 60
#define eps 1e-7
#define PP (3.141592653589793238)
using namespace std; int dcmp(double x)
{
if(fabs(x)<eps) return 0;
else return x<0?-1:1;
}
double toRad(double deg)
{
return deg/180.0*acos(-1.0);
}
struct Point
{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y) {}
void input()
{
scanf("%lf %lf",&x,&y);
}
};
typedef Point Vector; Vector operator+( Vector A, Vector B )
{
return Vector( A.x + B.x, A.y + B.y );
}
Vector operator-(Vector A,Vector B)
{
return Vector( A.x - B.x, A.y - B.y );
}
Vector operator*( Vector A, double p )
{
return Vector( A.x * p, A.y * p );
}
Vector operator/( Vector A, double p )
{
return Vector( A.x / p, A.y / p );
}
bool operator<(const Point& A, const Point& B )
{
return dcmp( A.x - B.x ) < 0 || ( dcmp( A.x - B.x ) == 0 && dcmp( A.y - B.y ) < 0 );
}
bool operator==( const Point& a, const Point& b )
{
return dcmp( a.x - b.x ) == 0 && dcmp( a.y - b.y ) == 0;
}
struct Line
{
Point s,e;
Vector v;
Line() {}
Line(Point s,Point v,int type):
s(s),v(v){}
Line(Point s,Point e):s(s),e(e)
{v=e-s;} };
double Dot(Vector A,Vector B)
{
return A.x*B.x+A.y*B.y;
}
double Length(Vector A)
{
return sqrt(Dot(A,A));
}
double Angle(Vector A,Vector B)
{
return acos(Dot(A,B)/Length(A)/Length(B));
}
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
double Area2(Point A,Point B,Point C )
{
return Cross(B-A,C-A);
}
double Dist(Point A,Point B)
{
return Length(A-B);
}
Vector Rotate(Vector A, double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
Vector Normal(Vector A)
{
double L=Length(A);
return Vector(-A.y/L,A.x/L);
}
Point GetLineIntersection(Line l1,Line l2)
{
Point P=l1.s;
Vector v=l1.v;
Point Q=l2.s;
Vector w=l2.v;
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
}
double DistanceToLine(Point P,Line L)
{
Point A,B;
A=L.s,B=L.e;
Vector v1=B-A,v2=P-A;
return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(Point P, Line L)
{
Point A,B;
A=L.s,B=L.e;
if(A==B) return Length(P-A);
Vector v1=B-A,v2=P-A,v3=P-B;
if (dcmp(Dot(v1,v2))<0) return Length(v2);
else if (dcmp(Dot(v1,v3))>0) return Length(v3);
else return fabs(Cross(v1,v2)) / Length(v1);
}
Point GetLineProjection(Point P,Line L)
{
Point A,B;
A=L.s,B=L.e;
Vector v=B-A;
return A+v*(Dot(v,P-A)/Dot(v,v));
} double abss(double x)
{
return x < 0 ? -x : x;
} bool OnSegment(Point p,Line l)
{
Point a1=l.s;
Point a2=l.e;
return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dist(p,a1)+Dist(p,a2)-Dist(a1,a2))==0;
}
bool Paralled(Line l1,Line l2)
{
return dcmp(Cross(l1.e-l1.s,l2.e-l2.s))==0;
}
bool SegmentProperIntersection(Line l1,Line l2)
{
if(Paralled(l1,l2))
{
return false;
}
Point t=GetLineIntersection(l1,l2);
if(OnSegment(t,l1))
{
return true;
}
return false;
} int main ()
{
double x ,y ,p;
int T ,n ,i;
scanf("%d" ,&T);
while(T--)
{
scanf("%d" ,&n);
double nowx1 = 0 ,nowy1 = 0;
double nowx2 = 0 ,nowy2 = 101.0;
double sss = 0;;
Vector A ,B;
for(i = 1 ;i <= n ;i ++)
{
scanf("%lf %lf %lf" ,&x ,&y ,&p);
if(p == 0.0 || abss(p - PP * 2) <= 0.00001) continue;
sss += p;
A.x = nowx1 - x ,A.y = nowy1 - y;
B = Rotate(A ,p);
nowx1 = x + B.x ,nowy1 = y + B.y;
A.x = nowx2 - x ,A.y = nowy2 - y;
B = Rotate(A ,p);
nowx2 = x + B.x ,nowy2 = y + B.y;
}
if(nowx1 == 0.0 && nowy1 == 0.0)
{
double x4 = nowx2 ,y4 = nowy2;
double x3 = 0 ,y3 = 0;
double x1 = 0 ,y1 = 101.0;
double aaa;
double tmp = (x4 - x3) * (x1 - x3) + (y4 - y3) * (y1 - y3);
tmp = tmp / (pow(x4 - x3 ,2.0) + pow(y4 - y3 ,2.0));
aaa = acos(tmp);
double q1 = 0 ,q2 = 0;
if(nowx2 > 0.0) aaa = PP * 2 - aaa;
if(abss(aaa - PP * 2) <= 0.00001)aaa = 0;
printf("%lf %lf %lf\n" ,q1 ,q2 ,aaa);
}
else if(nowx2 == 0.0 && nowy2 == 101.0)
{
double x4 = nowx1 ,y4 = nowy1;
double x3 = 0 ,y3 = 101.0;
double x1 = 0 ,y1 = 0;
double aaa;
double tmp = (x4 - x3) * (x1 - x3) + (y4 - y3) * (y1 - y3);
tmp = tmp / (pow(x4 - x3 ,2.0) + pow(y4 - y3 ,2.0));
aaa = acos(tmp);
double q1 = 0 ,q2 = 101.0;
if(nowx1 < 0) aaa = PP * 2 - aaa;
if(abss(aaa - PP * 2) <= 0.00001)aaa = 0;
printf("%lf %lf %lf\n" ,q1 ,q2 ,aaa);
}
else
{
Point AA1;
AA1.x = AA1.y = 0;
Point BB1;
BB1.x = nowx1 ,BB1.y = nowy1;
Line now1 = Line((AA1 + BB1)/2 ,Normal(AA1 - BB1),1);
Point AA2;
AA2.x = 0 ,AA2.y = 101.0;
Point BB2;
BB2.x = nowx2 ,BB2.y = nowy2;
Line now2 = Line((AA2 + BB2)/2 ,Normal(AA2 - BB2),1);
Point now = GetLineIntersection(now1 ,now2);
double x4 = nowx1 ,y4 = nowy1;
double x3 = now.x ,y3 = now.y;
double x1 = 0 ,y1 = 0;
double aaa;
double tmp = (x4 - x3) * (x1 - x3) + (y4 - y3) * (y1 - y3);
tmp = tmp / (pow(x4 - x3 ,2.0) + pow(y4 - y3 ,2.0));
double x2 ,y2;
x1 = 0 ,y1 = 101;
x2 = nowx2 - nowx1 ,y2 = nowy2 - nowy1;
aaa = acos(tmp);
if(x1*y2-x2*y1<0) aaa = PP * 2 - aaa;
printf("%lf %lf %lf\n" ,now.x ,now.y ,aaa);
}
}
return 0;
}
hdu4998 旋转坐标系的更多相关文章
- VPython—旋转坐标系
使用arrow( )创建三个坐标轴代表一个坐标系,其中X0-Y0-Z0为参考坐标系(固定不动),X-Y-Z为运动坐标系,这两个坐标系原点重合,运动坐标系可以绕参考坐标系或其自身旋转.在屏幕上输出一个转 ...
- 【bzoj3170】[Tjoi 2013]松鼠聚会 旋转坐标系
题目描述 有N个小松鼠,它们的家用一个点x,y表示,两个点的距离定义为:点(x,y)和它周围的8个点即上下左右四个点和对角的四个点,距离为1.现在N个松鼠要走到一个松鼠家去,求走过的最短距离. 输入 ...
- 【bzoj2989】数列 KD-tree+旋转坐标系
题目描述 给定一个长度为n的正整数数列a[i]. 定义2个位置的graze值为两者位置差与数值差的和,即graze(x,y)=|x-y|+|a[x]-a[y]|. 2种操作(k都是正整数): 1.Mo ...
- [bzoj2989]数列_KD-Tree_旋转坐标系
数列 bzoj-2989 题目大意:题目链接. 注释:略. 想法:显然,我们用x和a[x]两个值建立笛卡尔坐标系. 两个点之间的距离为曼哈顿距离. 修改操作就是插入... 查询操作就是查询一个点周围的 ...
- [SDOI2018]物理实验 set,扫描线,旋转坐标系
[SDOI2018]物理实验 set,扫描线,旋转坐标系 链接 loj 思路 先将导轨移到原点,然后旋转坐标系,参考博客. 然后分线段,每段的贡献(三角函数值)求出来,用自己喜欢的平衡树,我选set. ...
- HDU 6538 Neko and quadrilateral(极角排序+旋转坐标系)
这道题简直太好了,对于计算几何选手需要掌握的一个方法. 首先对于求解四边形面积,我们可以将四边形按对角线划分成两个三角形,显然此时四边形的面积最大最小值就变成了求解里这个对角线最近最远的点对. 对于此 ...
- Android canvas rotate():平移旋转坐标系至任意原点任意角度-------附:android反三角函数小结
自然状态下,坐标系以屏幕左上角为原点,向右是x正轴,向下是y正轴.现在要使坐标系的原点平移至任一点O(x,y),且旋转a角度,如何实现? 交待下我的问题背景,已知屏幕上有两点p1和p2,构成直线l.我 ...
- 【bzoj3210】花神的浇花集会 旋转坐标系
题目描述 在花老师的指导下,每周4都有一个集会活动,俗称“浇水”活动. 具体浇水活动详情请见BZOJ3153 但这不是重点 花神出了好多题,每道题都有两个参考系数:代码难度和算法难度 花神为了准备浇花 ...
- 【bzoj1604】[Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 旋转坐标系+并查集+Treap/STL-set
题目描述 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”.每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l≤Xi,Yi≤ ...
随机推荐
- PAT-1086(Tree Traversals Again)Java语言实现+根据中序和前序遍历构建树并且给出后序遍历序列
Tree Traversals Again Tree Traversals Again 这里的第一个tip就是注意到非递归中序遍历的过程中,进栈的顺序恰好是前序遍历的顺序,而出栈的顺序恰好是中序遍历的 ...
- Java的封装继承和多态
封装 定义:属性私有private:get/set 目的 提高程序的安全性,保护数据 隐藏代码的实现细节 统一接口 提高系统的可维护性 代码 public class Student { //名字 p ...
- 还在用crontab? 分布式定时任务了解一下
前言 日常任务开放中,我们会有很多异步.批量.定时.延迟任务要处理,go-zero中有 go-queue,推荐使用 go-queue 去处理,go-queue 本身也是基于 go-zero 开发的,其 ...
- win8 下删除服务
1.右键 我的电脑-管理-服务和应用程序-服务,找到想要删除的服务,双击后复制服务名称. 2.管理员身份运行cmd 在命令框中输入 sc delete "secbizsrv" 就删 ...
- Ignatius and the Princess III HDU - 1028
题目传送门:https://vjudge.net/problem/HDU-1028 思路:整数拆分构造母函数的模板题 1 //#include<bits/stdc++.h> 2 #incl ...
- 使用命令行编译Qt程序
code[class*="language-"], pre[class*="language-"] { color: rgba(51, 51, 51, 1); ...
- java例题_41 利用递归给猴子分桃
1 /*41 [程序 41 猴子分桃] 2 题目:海滩上有一堆桃子,五只猴子来分.第一只猴子把这堆桃子平均分为五份,多了一个,这只猴子把 3 多的一个扔入海中,拿走了一份.第二只猴子把剩下的桃子又平均 ...
- Android学习之探究Fragment
•碎片是什么 Fragment是一种可以嵌入在活动中的UI片段,能够让程序更加合理和充分地利用大屏幕的空间: 出现的初衷是为了适应大屏幕的平板电脑,可以将其看成一个小型Activity,又称作Acti ...
- 力扣 - 92. 反转链表II
目录 题目 思路1(迭代) 代码 复杂度分析 思路2(递归) 代码 复杂度分析 题目 92. 反转链表 II 思路1(迭代) 将反转链表分成3个部分:前一段未反转的部分.待反转链表部分.后一段未反转部 ...
- 以绝对优势立足:从CDN和云存储来聊聊云生态的崛起
以绝对优势立足:从CDN和云存储来聊聊云生态的崛起 前面几期文章我们介绍了混合云模式,以及面向应用层的云架构解决方案的Spring Cloud.接下来,我们就以蘑菇街的两个具体案例,来分享一下基于混合 ...