题目大意:n个向量首尾相连,每次操作使某个区间中的所有向量都旋转同样的角度。每次操作后都回答最后一个向量的坐标。

题目分析:区间维护向量信息。向量旋转:x1=x0*cos(t)-y0*sin(t),y1=x0*sin(t)+y0*cos(t),其中t为旋转的角度。

代码如下:

# include<iostream>
# include<cmath>
# include<algorithm>
# include<cstdio>
using namespace std;
# define mid (l+(r-l)/2) const int N=10005;
const double PI=acos(-1.0); double x[N<<2],y[N<<2];
int lazy[N<<2];
int angle[N]; inline void read(int &x)
{
x=0;
char c;
while((c=getchar())&&(c<'0'||c>'9'));
x=c-'0';
while(c=getchar()){
if(c<'0'||c>'9') break;
x=x*10+c-'0';
}
} inline double f(int x)
{
return x*PI/180.0;
} inline void pushUp(int rt)
{
x[rt]=x[rt<<1]+x[rt<<1|1];
y[rt]=y[rt<<1]+y[rt<<1|1];
} inline void pushDown(int rt)
{
if(lazy[rt]==0) return ;
lazy[rt<<1]+=lazy[rt];
lazy[rt<<1|1]+=lazy[rt]; double xx=x[rt<<1];
double yy=y[rt<<1];
x[rt<<1]=xx*cos(f(lazy[rt]))-yy*sin(f(lazy[rt]));
y[rt<<1]=xx*sin(f(lazy[rt]))+yy*cos(f(lazy[rt])); xx=x[rt<<1|1];
yy=y[rt<<1|1];
x[rt<<1|1]=xx*cos(f(lazy[rt]))-yy*sin(f(lazy[rt]));
y[rt<<1|1]=xx*sin(f(lazy[rt]))+yy*cos(f(lazy[rt]));
lazy[rt]=0;
} inline void build(int rt,int l,int r)
{
lazy[rt]=0;
if(l==r){
x[rt]=0.0;
int a;
read(a);
y[rt]=a;
}else{
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
pushUp(rt);
}
} inline void update(int rt,int l,int r,int L,int R,int a)
{
if(L<=l&&r<=R){
lazy[rt]+=a;
double xx=x[rt];
double yy=y[rt];
x[rt]=xx*cos(f(a))-yy*sin(f(a));
y[rt]=xx*sin(f(a))+yy*cos(f(a));
}else{
pushDown(rt);
if(L<=mid) update(rt<<1,l,mid,L,R,a);
if(R>mid) update(rt<<1|1,mid+1,r,L,R,a);
pushUp(rt);
}
} int main()
{
int n,m;
bool first=true;
while(~scanf("%d%d",&n,&m))
{
if(!first) puts("");
first=false;
build(1,0,n-1);
for(int i=0;i<n;++i)
angle[i]=180;
int a,b;
while(m--){
scanf("%d%d",&a,&b);
update(1,0,n-1,a,n-1,b-angle[a-1]);
angle[a-1]=b;
printf("%.2lf %.2lf\n",x[1],y[1]);
}
}
return 0;
}

  

POJ-2991 Crane(区间更新+向量旋转)的更多相关文章

  1. [poj 2991]Crane[线段树表示向量之和,而非数量]

    题意: 起重机的机械臂, 由n段组成, 对某一些连接点进行旋转, 询问每次操作后的末端坐标. 思路: 由于旋转会影响到该点之后所有线段的角度, 因此容易想到用线段树记录角度, 成段更新. (但是不是每 ...

  2. POJ 2991 Crane(线段树+计算几何)

    POJ 2991 Crane 题目链接 题意:给定一个垂直的挖掘机臂.有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标 思路:线段树.把每一段当成 ...

  3. (中等) POJ 2991 Crane , 几何+线段树。

    Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...

  4. POJ 2991 Crane (线段树)

    题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...

  5. POJ - 2991 Crane (段树+计算几何)

    Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...

  6. POJ 2991–Crane【线段树+几何】

    题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...

  7. POJ 2991 Crane

    线段树+计算几何,区间更新,区间求和,向量旋转. /* *********************************************** Author :Zhou Zhentao Ema ...

  8. C - A Simple Problem with Integers - poj 3468(区间更新)

    题意:有一个比较长的区间可能是100000.长度, 每个点都有一个值(值还比较大),现在有一些操作,C abc, 把区间a-b内全部加上c, Qab,求区间ab的值. 分析:很明显我们不可能对区间的每 ...

  9. POJ 2991 Crane(线段树)

    Crane Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7687   Accepted: 2075   Special J ...

随机推荐

  1. C/C++文件结构

    总结者:kate (1).h 为头文件:存放 版权和版本声明,预处理块 ,函数和类结构声明 (2).cpp文件:代码文件,存放程序的实现 大都数时候,源文件和头文件是对应出现的,比如有一个A.cpp  ...

  2. 记录一些容易忘记的属性 -- UIKeyboard

    //UIKeyboardWillShowNotification这个通知在软键盘弹出时由系统发送    //UIKeyboardWillShowNotification 通知:键盘将要显示的通知    ...

  3. 调整label中text显示的行间距

    调整label中text显示的行间距最近再做一个项目时,发现UILabel中text的系统默认行间距不能满足要求,于是在网上找到了调整行间距的代码.跟大家分享一下,希望能对你有所帮助.悦德财富:htt ...

  4. iOS闪烁效果工具 GlitchLabel

    GlitchLabel 用于给文字添加闪烁效果,效果图如下: 开发环境: iOS 7.0+ Swift 2.2 Xcode 7 示例代码:https://www.yuedecaifu.com 1 2 ...

  5. Format a Hard Drive in Csharp C#格式化总结

    using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Management; ...

  6. Linux文件管理系统

    首先了解一般linux文件系统的构成. */usr/bin./bin : 存放所有用户可以执行的命令 */usr/sbin ./sbin :存放只有root可以执行的命令 */home : 用户缺省宿 ...

  7. 关于高并发的aotomic

    AtomicInteger线程安全的根源,熟悉并发的同学一定知道在java中处理并发主要有两种方式: 1,synchronized关键字,这个大家应当都各种面试和笔试中经常遇到. 2,volatile ...

  8. Thread启动方式一(Thread.start):源码分析

    package day11; class TestDemo extends Thread{ int count = 0; /*public void add(){ while(count<100 ...

  9. 解决win7资源监视器不能开启

    刚开始时是这样,点击开始监控,无效 需要开始服务即可解决

  10. Ubuntu 14.10 下网络流量实时监控ifstat iftop命令详解

    ifstat 介绍 ifstat工具是个网络接口监测工具,比较简单看网络流量 实例 默认使用 #ifstat eth0 eth1 KB/s in KB/s out KB/s in KB/s out 0 ...