线段树+计算几何,区间更新,区间求和,向量旋转。

/* ***********************************************
Author :Zhou Zhentao
Email :774388357@qq.com
Created Time :2015/11/27 9:58:30
File Name :main.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const int maxn=+;
const double pi= acos(-1.0);
struct SegTree
{
double SumX,SumY;//记录向量
int add;//延迟更新的标记,记录角度转变量
}st[maxn*];
int f[maxn];
int N,Q; double H(double x)
{
return x*pi/180.0;
} void Rot(int rt,double A)
{
double NewX,NewY;
NewX=st[rt].SumX*cos(H(A))-st[rt].SumY*sin(H(A));
NewY=st[rt].SumX*sin(H(A))+st[rt].SumY*cos(H(A));
st[rt].SumX=NewX;
st[rt].SumY=NewY;
} void pushUp(int rt)
{
st[rt].SumX=st[rt*].SumX+st[rt*+].SumX;
st[rt].SumY=st[rt*].SumY+st[rt*+].SumY;
} void pushDown(int rt)
{
if(st[rt].add)
{
st[*rt].add+=st[rt].add;
st[*rt+].add+=st[rt].add;
Rot(*rt,(double)st[rt].add);
Rot(*rt+,(double)st[rt].add);
st[rt].add=;
}
} void build(int l,int r,int rt)
{
st[rt].add=;
if(l==r)
{
scanf("%lf",&st[rt].SumY);
st[rt].SumX=;
return;
}
int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+);
pushUp(rt);
} void update(int L,int R,int add,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
st[rt].add+=add;
Rot(rt,(double)add);
return;
} pushDown(rt);
int m=(l+r)/;
if(L<=m) update(L,R,add,l,m,*rt);
if(R>=m+) update(L,R,add,m+,r,*rt+);
pushUp(rt);
} int main()
{ int tot=;
while(~scanf("%d%d",&N,&Q))
{
if(tot) printf("\n");tot=; build(,N,); for(int i=;i<=N;i++) f[i]=; for(int i=;i<=Q;i++)
{
int x;int y;
scanf("%d%d",&x,&y);
int A=y-f[x];
update(x+,N,A,,N,);
f[x]=y; printf("%.2lf %.2lf\n",st[].SumX,st[].SumY);
}
}
return ;
}

POJ 2991 Crane的更多相关文章

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

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

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

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

  3. POJ 2991 Crane(线段树)

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

  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[线段树表示向量之和,而非数量]

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

  8. AC日记——Crane poj 2991

    POJ - 2991 思路: 向量旋转: 代码: #include <cmath> #include <cstdio> #include <cstring> #in ...

  9. Crane (POJ 2991)

    //线段树 延迟标签 // #include <bits/stdc++.h> using namespace std; const int maxn=1e4+5; double x[max ...

随机推荐

  1. Windows使用小技巧

    一.windows7 系统切换到 administrator用户 先进入windows 7的安全模式.. (这你应该会吧?) 然后系统会自动调出用administrator 帐号登录.. 密码你必须要 ...

  2. Chapter 2 Open Book——12

    I called him in when dinner was ready, and he sniffed appreciatively as he walked into the room. 当晚饭 ...

  3. Handling Captcha | Webdriver

    http://seleniumworks.blogspot.kr/2013/09/handling-captcha-webdriver.html Make use of the 'input' tag ...

  4. C++中为什么构造函数初始化列表

    已经有个构造函数负责初始化,为什么还需要构造函数初始化表呢? 在以下三种情况下需要使用初始化成员列表:一,需要初始化的数据成员是对象的情况:二,需要初始化const修饰的类成员:三,需要初始化引用成员 ...

  5. Unity3d 物体沿着正七边形轨迹移动

    不对之处,敬请谅解. 1.圆内接正七边形半径 public static float r = 10; 2.存储七个顶点的值 Vector3[] ar = new Vector3[7]; 3.圆心角 s ...

  6. to_date()与to_char()

    1.以时间(Date类型)为查询条件时,可以用to_date函数实现: select t.* from D101 t where t.d101_40 = to_date('2013/9/12', 'y ...

  7. js.map error

    1. 问题:      1.1 通过bower install 的components 许多在运行的时候报404无法找到js.map文件, 如图:          2. 分析:     2.1 查看 ...

  8. Spotlights

    Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. PHP配置安全小技巧

  10. CDialog上使用CToolBar+CReBar

    最经在做一些用户界面的东西,对话框上有很多按钮和组合框,全部加起来差不多有20多个吧,界面非常凌乱,最后决定用CToolBar + CReBar来重新设计界面,为什么选用这个呢?一是因为看到IE用的也 ...