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 ...
随机推荐
- 第三十节,正则表达式re模块
正则表达式 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序员们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引 ...
- LeetCode OJ 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- linux 进程监控和自动重启的简单实现(转)
目的:linux 下服务器程序会因为各种原因dump掉,就会影响用户使用,这里提供一个简单的进程监控和重启功能. 实现原理:由定时任务crontab调用脚本,脚本用ps检查进程是否存在,如果不存在则重 ...
- laravel路由使用【总结】
1.路由参数 必选参数 有时我们需要在路由中捕获 URI 片段.比如,要从 URL 中捕获用户 ID,需要通过如下方式定义路由参数: Route::get('/test_param/{id}', 'T ...
- Inno Setup入门(二十)——Inno Setup类参考(6)
存储框 存储框也是典型的窗口可视化组件,同编辑框类似,可以输入.显示文本,但是和编辑框不同的是,编辑框只能编辑.显示单行文本,而存储框则可以对多行文本进行操作.存储框的类定义如下:< xmlna ...
- openCV(四)---Canny边缘检测
图像的边缘检测的原理是检测出图像中所有灰度值变化较大的点,而且这些点连接起来就构成了若干线条,这些线条就可以称为图像的边缘. 直接上代码,函数简介都在代码注释中 //canny边缘检测 -(void) ...
- on使用详解
on()是bind(),live(),delegate()的替代品,1.7及1.7以后使用on() bind() 绑定元素 live() 为元素附加事件,匹配选择器的当前及未来的元素(比如由脚本创建的 ...
- 转 : net use的使用
老是忘了 net use 怎么样,今天在网上找一篇,贴在这,感谢原作者分享. 1 查看远程主机的共享资源(但看不到默认共享) net view \\IP 2向远程主机复制文件 copy \路径 ...
- 在PL/SQL/sqlplus客户端 中如何让程序暂停几秒钟
1. how to check procedure exist: SQL> conn oper/oper123Connected.SQL> desc dbms_lock;PROCEDURE ...
- java跳过构造方法新建对象
Java有四种创建对象的方法: (1) 用new语句创建对象,这是最常见的创建对象的方法. (2) 运用反射手段,调用java.lang.Class或者java.lang.reflect.Constr ...