POJ 2991 Crane
线段树+计算几何,区间更新,区间求和,向量旋转。
/* ***********************************************
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的更多相关文章
- POJ 2991 Crane(线段树+计算几何)
POJ 2991 Crane 题目链接 题意:给定一个垂直的挖掘机臂.有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标 思路:线段树.把每一段当成 ...
- (中等) POJ 2991 Crane , 几何+线段树。
Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...
- POJ 2991 Crane(线段树)
Crane Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7687 Accepted: 2075 Special J ...
- POJ 2991 Crane (线段树)
题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...
- POJ - 2991 Crane (段树+计算几何)
Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...
- POJ 2991–Crane【线段树+几何】
题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...
- [poj 2991]Crane[线段树表示向量之和,而非数量]
题意: 起重机的机械臂, 由n段组成, 对某一些连接点进行旋转, 询问每次操作后的末端坐标. 思路: 由于旋转会影响到该点之后所有线段的角度, 因此容易想到用线段树记录角度, 成段更新. (但是不是每 ...
- AC日记——Crane poj 2991
POJ - 2991 思路: 向量旋转: 代码: #include <cmath> #include <cstdio> #include <cstring> #in ...
- Crane (POJ 2991)
//线段树 延迟标签 // #include <bits/stdc++.h> using namespace std; const int maxn=1e4+5; double x[max ...
随机推荐
- Centos7下安装numpy+matplotlib+scipy
摘自:http://litchiware.github.io/centos/2015/07/05/centos7%E4%B8%8B%E5%AE%89%E8%A3%85numpy+matplotlib+ ...
- 妙用transform
往前移动 transform.Translate transform.Translate( transform.up* speed*Time.deltaTime , Space.World); 移动t ...
- iOS申请真机调试证书 -- 图文详解
请参考这篇文章 : http://ios.9tech.cn/news/2013/1011/33117.html 这篇文章完全就是对的,主要是最后一步 “配置Xcode" 图没有配全,也配得不 ...
- Floodfill算法——求独立子图个数
Floodfill--漫水填充法(也称种子填充法)简单来说就是求一个图中独立子图的个数并将其描述出不同的状态.Floodfill在计算机图形学有着非常广泛的运用,比如图像分割.物体识别之类.基于Flo ...
- div style设置隐藏多余字, title设置鼠标放上显示出来全部
<div style='overflow: hidden; white-space: nowrap; text-overflow: ellipsis;' title='"+data[j ...
- Thinkphp中使用Redis
先确保安装了redis扩展 添加Redis配置 'REDIS_HOST'=>'192.168.0.2', 'REDIS_PORT'=>6379, 其他配置根据自己ThinkPHP版本,找到 ...
- mynotebook
www.linux.org/threads/beats-audio-on-linux.4443/ askubuntu.com/questions/303775/envy-15-beats-audio- ...
- Python 入门基础学习
Python入门学习 我们使用python3.0版本 首选来入门 带你进入Hello World >>> print ("Hello World")Hell ...
- 常用的opengl函数(三)
glBlendFunc 定义像素算法. void WINAPI glBlendFunc(GLenum sfactor,GLenum dfactor); 参数编辑 sfactor 指定红绿蓝和 al ...
- NPAPI简介
原文出处:http://blog.csdn.net/wwwsq/article/details/8254911 NPAPI是电脑上大部分非ie浏览器都支持的一种浏览器扩展,类似ie的activex技术 ...