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

/* ***********************************************
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. shell:crontab

    crontab */1 * * * * (cd /home/q/system/project; /usr/bin/lockf -t 0 /tmp/discuz_bbs_audit.lock /usr/ ...

  2. 克隆虚拟机系统整个文件快照,然后另起建立该系统,产生的IP地址冲突解决办法

    进入克隆后的文件系统 cd /etc/sysconfig/network-scripts/ cp ifcfg-eth0  ifcfg-eth1 vim ifcfg-eth1   #修改其中的文件内容 ...

  3. 命名空间“Microsoft”中不存在类型或命名空间名称“Office”(是缺少程序集引用吗?)

    通过引用这个解决,不同的的office版本,中间的版本号可能不同,如图所示:

  4. flex日期合并与拆分

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  5. 使用anyremote进行远程鼠标控制

    源代码安装 http://anyremote.sourceforge.net/pre.html 安装  -xtest apt-get install libxtst-dev 安装 glib sudo ...

  6. nm applet disable

    http://support.qacafe.com/knowledge-base/how-do-i-prevent-network-manager-from-controlling-an-interf ...

  7. STM32F4系统时钟配置及描述

    STM32F4系统时钟配置及描述 stm32f407时钟配置方法(感觉很好,分享一下) STM32F4_RCC系统时钟配置及描述 STM32F4时钟设置分析 stm32f4 - 时钟树分析配置

  8. 在ASP.Net中"../" "./" "~/"表示的意思

    "../" 相对当前(根据不同的语境,当前是不同的)的上一级目录"./" 就是当前目录 "~/" 当前项目的根路径,只在服务器端有效.

  9. 怎样让pl sql developer 界面视图复位

    tools->preferences->user interface->appearance->reset docking工具-首选项-用户界面-外观-复位停放

  10. springAOP 的pointcut

    <bean id="amqFilter" class="com.xxx.hotel.base.aspectj.AmQConsumerFilter"/> ...