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

Description

ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of various lengths, connected by flexible joints. The end of the i-th segment is joined to the beginning of the i + 1-th one, for 1 ≤ i < n. The beginning of the first segment is fixed at point with coordinates (0, 0) and its end at point with coordinates (0, w), where w is the length of the first segment. All of the segments lie always in one plane, and the joints allow arbitrary rotation in that plane. After series of unpleasant accidents, it was decided that software that controls the crane must contain a piece of code that constantly checks the position of the end of crane, and stops the crane if a collision should happen.

Your task is to write a part of this software that determines the position of the end of the n-th segment after each command. The state of the crane is determined by the angles between consecutive segments. Initially, all of the angles are straight, i.e., 180o. The operator issues commands that change the angle in exactly one joint. 

Input

The input consists of several instances, separated by single empty lines.

The first line of each instance consists of two integers 1 ≤ n ≤10 000 and c 0 separated by a single space -- the number of segments of the crane and the number of commands. The second line consists of n integers l1,..., ln (1 li 100) separated by single spaces. The length of the i-th segment of the crane is li. The following c lines specify the commands of the operator. Each line describing the command consists of two integers s and a (1 ≤ s < n, 0 ≤ a ≤ 359) separated by a single space -- the order to change the angle between the s-th and the s + 1-th segment to a degrees (the angle is measured counterclockwise from the s-th to the s + 1-th segment).

Output

The output for each instance consists of c lines. The i-th of the lines consists of two rational numbers x and y separated by a single space -- the coordinates of the end of the n-th segment after the i-th command, rounded to two digits after the decimal point.

The outputs for each two consecutive instances must be separated by a single empty line.

Sample Input

2 1
10 5
1 90 3 2
5 5 5
1 270
2 90

Sample Output

5.00 10.00

-10.00 5.00
-5.00 10.00

Source

 
节点i表示的向量是vxi,vyi,角度是angi,两个儿子节点是chl和chr,
 
vx[i]=vx[chl]+ (cos(angi)*vx[chr]-sin(angi)*vy[chr]);
vy[i]=vy[chl]+ (sin(angi)*vx[chr]+cos(angi)*vy[chr]);
 
 #include <iostream>
#include <cmath>
#include <cstdio>
#define MAX_N 10000
#define M_PI 3.14159265358979323846
using namespace std; const int ST_SIZE=(<<)-;
//输入
int N,C;
int L[MAX_N+];
int S[MAX_N+],A[MAX_N+]; //线段树所维护的数据
double vx[ST_SIZE],vy[ST_SIZE];
double ang[ST_SIZE]; //为了查询角度的变化而保存的当前角度的数组
double prv[MAX_N]; //初始化线段树
//k是节点的编号,l,r表示当前节点对应的是[l,r]区间
void init(int k,int l,int r)
{
ang[k]=vx[k]=0.0;
if(r-l==)
{
//叶子节点
vy[k]=L[l];
}
else
{
//非叶子节点
int chl=k*+,chr=k*+;
init(chl,l,(l+r)/);
init(chr,(l+r)/,r);
vy[k]=vy[chl]+vy[chr];
}
}
//把s和s+1的角度变为a
//v是节点的编号,,l,r表示当前节点对应的是[l,r]区间
void change(int s,double a,int v,int l,int r)
{
if(s<=l)
return;
else if(s<r)
{
int chl=v*+,chr=v*+;
int m=(l+r)/;
change(s,a,chl,l,m);
change(s,a,chr,m,r);
if(s<=m)
ang[v]+=a;
double s=sin(ang[v]),c=cos(ang[v]); //围绕原点的旋转:
vx[v]=vx[chl]+(c*vx[chr]-s*vy[chr]); //x' = x * cos(a) - y * sin(a)
vy[v]=vy[chl]+(s*vx[chr]+c*vy[chr]); //y' = x * sin(a) + y * cos(a)
} }
void solve()
{
//初始化
init(,,N);
for(int i=;i<N;i++)
prv[i]=M_PI;
//处理操作
for(int i=;i<C;i++)
{
int s=S[i];
double a=A[i]/360.0**M_PI; //把角度换算为弧度
change(s,a-prv[s],,,N);
prv[s]=a;
printf("%.2f %.2f\n",vx[],vy[]); } }
int main()
{
while(cin>>N>>C)
{
for(int i=;i<N;i++)
scanf("%d",&L[i]);
for(int i=;i<C;i++)
scanf("%d%d",&S[i],&A[i]);
solve(); } return ;
}

POJ 2991 Crane(线段树)的更多相关文章

  1. [poj 2991]Crane[线段树表示向量之和,而非数量]

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

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

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

  3. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  4. Buy Tickets POJ - 2828 思维+线段树

    Buy Tickets POJ - 2828 思维+线段树 题意 是说有n个人买票,但是呢这n个人都会去插队,问最后的队列是什么情况.插队的输入是两个数,第一个是前面有多少人,第二个是这个人的编号,最 ...

  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 (线段树)

    题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...

  7. POJ 2991–Crane【线段树+几何】

    题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...

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

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

  9. poj 3264(线段树)

    http://poj.org/problem?id=3264 初学线段可以做的水题,也是线段树的基础运用.也是我的第一个线段树的题. 题意:在区间范围内的最大值减去最小值 思路:线段树记录下每个区间内 ...

随机推荐

  1. RESTful设计方法

    REST REST,即Representational State Transfer的缩写.维基百科称其为“具象状态传输”,国内大部分人理解为“表现层状态转化”. RESTful是一种开发理念.维基百 ...

  2. PHP use

    PHP 7 use 语句  PHP 7 新特性 PHP 7 可以使用一个 use 从同一个 namespace 中导入类.函数和常量: 实例 实例 // PHP 7 之前版本需要使用多次 use us ...

  3. Makefile特殊标签

    http://www.gnu.org/software/make/manual/html_node/Special-Targets.html

  4. windows7 下python3.6 下Scripts文件夹为空

    windows7 下python3.6 下Scripts文件夹为空,安装后不能运行pip,这个时候输入命令: python -m ensurepip 会自动安装pip,然后运行pip3 list就可以 ...

  5. Kotlin Reference (二) Idioms

    most from reference 一些常用操作 创建单例类 object 数据类data classList.Map.Array的简单操作Lazy延迟加载属性空类型?空类型表达式?..?:.?. ...

  6. iOS的坑:ERRORITMS-90096: "Your binary is not optimized for iPhone 5 - New iPhone appsand app updatesXcode7提交到App Store二进制文件时报错错误:“你itms-90096二进制不是iPhone 5的新iPhone应用程序和应用程序的更新必须提交支持iPhone 5英寸的显示器........

    在工程里的Images.xcassets添加并设置LaunchImage对解决ERROR ITMS-90096根本不会起到任何作用,需要单独添加针对iPhone 5的载入图片.关键点有三项: 1.图片 ...

  7. 基于 od 窗口的anti

    虽然 odadvance 这类的插件 , 使用驱动将 od 的窗口 进行 隐藏,使用enumwindow ,无法枚举到od的窗口, 但是依然可以 使用r3 的方法 , 对od 窗口检测 之后可以使用 ...

  8. php安装完后配置php.ini和php-fpm.conf

    php.ini //错误日志级别 error_reporting = E_ALL //错误日志文件路径 error_log = /data/logs/php/php_errors.log //配置时区 ...

  9. 在exsi6.0中安装debian8.1 64位 无界面服务器版.

    之前介绍了exsi6.0的安装. 现在开始应用. 上一篇介绍的exsi6.0是安装在U盘上的系统.U盘为群联芯片,芯片型号为2251-50/30.容量为2G.发现容量足够用.比较节省成本. 现在开始为 ...

  10. 《DSP using MATLAB》示例Example 6.10

    上代码: % Pole-Zero IIR filter to Lattice-ladder structure filter b = [1, 2, 2, 1]; a = [1, 13/24, 5/8, ...