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

线段树维护角度,把线段看成向量然后旋转这个部分有点不好想

#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int MAXN=11111;
const double pi=acos(-1.0);
struct node
{
    double x,y;
}stree[MAXN<<2];
double cont[MAXN<<2];

void pushup(int rt){
    stree[rt].x=stree[rt<<1].x+stree[rt<<1|1].x;
    stree[rt].y=stree[rt<<1].y+stree[rt<<1|1].y;
}

void build(int l,int r,int rt)
{
    if(l==r)
    {
        double y;
        scanf("%lf",&y);
        stree[rt].x=0;
        stree[rt].y=y;
        return;
    }
    int mid=(l+r)>>1;
    build(lson);
    build(rson);
    pushup(rt);
}


void f(int rt,double at)
{
    double x=stree[rt].x;
    double y=stree[rt].y;
    stree[rt].x=x*cos(at)-y*sin(at);
    stree[rt].y=x*sin(at)+y*cos(at);
}

void pushdown(int rt)
{
    if(cont[rt]!=0)
    {
        cont[rt<<1]+=cont[rt];
        cont[rt<<1|1]+=cont[rt];
        f(rt<<1,cont[rt]);
        f(rt<<1|1,cont[rt]);
        cont[rt]=0;
    }
}
void update(int L,int R,double at,int l,int r,int rt)
{
    if(L<=l&&r<=R)
    {
        cont[rt]+=at;
        f(rt,at);
        return;
    }
    pushdown(rt);
    int mid=(l+r)>>1;
    if(L<=mid) update(L,R,at,lson);
    if(R>mid) update(L,R,at,rson);
    pushup(rt);
}
int main()
{
    int n,c;
    int kace=0;
    while(scanf("%d%d",&n,&c)!=EOF)
    {
        if(kace++) puts("");
        memset(cont,0,sizeof(cont));
        build(1,n,1);
        int angle[MAXN<<2];
        for(int i=1;i<=n;i++)
            angle[i]=180;
        while(c--)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            int at1=(b-angle[a]+360)%360;
            update(a+1,n,at1*1.0/180.0*pi,1,n,1);
            angle[a]=b;
            printf("%.2lf %.2lf\n",stree[1].x,stree[1].y);
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值