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

CTU Open 2005
 
 
题目大意:

题解:

我是没想到是线段树,看了是线段树后自己yy了一个建线段树的方法,好像跟书上的不一样。

书上的方法:

我的代码:

 program rrr(input,output);
const
eps=1e-10;
type
treetype=record
l,r:longint;
x,y,d:double;
end;
var
a:array[..]of treetype;
c:array[..]of double;
b:array[..]of longint;
n,m,i,x:longint;
y,t,xx,yy:double;
procedure build(k,l,r:longint);
var
mid,i:longint;
begin
a[k].l:=l;a[k].r:=r;a[k].x:=;a[k].d:=;
if l=r then begin a[k].y:=b[l];exit; end;
mid:=(l+r)>>;i:=k+k;
build(i,l,mid);build(i+,mid+,r);
a[k].y:=a[i].y+a[i+].y;
end;
procedure pushdown(k:longint);
var
i:longint;
begin
if a[k].l=a[k].r then a[k].d:=;
if abs(a[k].d)<eps then exit;
i:=k+k;
xx:=a[i].x*cos(a[k].d)-a[i].y*sin(a[k].d);
yy:=a[i].x*sin(a[k].d)+a[i].y*cos(a[k].d);
a[i].x:=xx;a[i].y:=yy;a[i].d:=a[i].d+a[k].d;
inc(i);
xx:=a[i].x*cos(a[k].d)-a[i].y*sin(a[k].d);
yy:=a[i].x*sin(a[k].d)+a[i].y*cos(a[k].d);
a[i].x:=xx;a[i].y:=yy;a[i].d:=a[i].d+a[k].d;
a[k].d:=;
end;
procedure change(k:longint);
var
mid,i:longint;
begin
pushdown(k);
if x<a[k].l then
begin
xx:=a[k].x*cos(t)-a[k].y*sin(t);
yy:=a[k].x*sin(t)+a[k].y*cos(t);
a[k].x:=xx;a[k].y:=yy;
a[k].d:=t;
exit;
end;
mid:=(a[k].l+a[k].r)>>;i:=k+k;
if x<mid then change(i);
change(i+);
a[k].x:=a[i].x+a[i+].x;a[k].y:=a[i].y+a[i+].y;
end;
begin
assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
while not eof do
begin
readln(n,m);if (n=) and (m=) then break;
for i:= to n do begin read(b[i]);c[i]:=pi; end;
build(,,n);
for i:= to m do
begin
readln(x,y);t:=y/*pi-c[x];c[x]:=y/*pi;
change();
writeln(a[].x::,' ',a[].y::);
end;
writeln;
end;
close(input);close(output);
end.

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

  1. poj2991 Crane(线段树+集合)白书例题

    题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现, ...

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

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

  3. (中等) POJ 2991 Crane , 几何+线段树。

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

  4. POJ 2991 Crane(线段树)

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

  5. POJ 2991 Crane (线段树)

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

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

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

  7. Crane /// 向量旋转+线段树

    题目大意: 给定n条首尾相接的线段的长度 第一条从0,0开始,所有线段垂直与x轴向上延伸 给定c次操作 每次操作给定 s,a 使得 由第s条线段的角度 逆时针旋转a后 达到第s+1条线段的角度 每次操 ...

  8. 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)

    转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...

  9. [转载]完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...

随机推荐

  1. JAVA 第二周学习总结

    20175308 2018-2019-2 <Java程序设计>第二周学习总结 教材学习内容总结: 第二章学习内容: 1.认识标识符与关键字 2.java的八种数据类型,着重记好精度由高到低 ...

  2. CSS grid layout

      CSS网格布局用于将页面分割成数个主要区域,或者用来定义组件内部元素间大小.位置和图层之间的关系. 像表格一样,网格布局让我们能够按行或列来对齐元素. 但是,使用CSS网格可能还是比CSS表格更容 ...

  3. scrapy (三)各部分意义及框架示意图详解

    一.框架示意图 Scrapy由 Python 编写,是一个快速.高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据.Scrapy用途广泛,可以用于数据挖掘.监测和自动化测试 ...

  4. 模拟T1数字number

    那么第一题首先非常水的一道题…… 看一下题 数字(number) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK拥有n个数,这n个数分别是a1,a2,… ...

  5. day 43

    今日内容 1.视图 2.事务 3.SQL注入问题 4.存储过程 首先回顾一下昨天所学 子查询: in (select a where 字段名 in select b) exists(判断后面语句执行结 ...

  6. Scala_数据类型

    Scala与Java有着相同的数据类型,Scala数据类型都是对象,Scala中没有类似Java中那样的原始类型. Scala 的基本数据类型有: Byte,Short,Int,Long 和 Char ...

  7. [CF1017G]The Tree[树链剖分+线段树]

    题意 给一棵一开始 \(n\) 个点全是白色的树,以 \(1\) 为根,支持三种操作: 1.将某一个点变黑,如果已经是黑色则该操作对所有儿子生效. 2.将一棵子树改成白色. 3.询问某个点的颜色. \ ...

  8. Java中Class类详解、用法及泛化

    Java中Class类及用法 Java程序在运行时,Java运行时系统一直对所有的对象进行所谓的运行时类型标识,即所谓的RTTI.这项信息纪录了每个对象所属的类.虚拟机通常使用运行时类型信息选准正确方 ...

  9. rabbitMQ教程(三)一篇文章看懂rabbitMQ

    一.rabbitMQ是什么: RabbitMQ,遵循AMQP协议,由内在高并发的erlanng语言开发,用在实时的对可靠性要求比较高的消息传递上. 学过websocket的来理解rabbitMQ应该是 ...

  10. centos7 php性能调优

    php-ini优化 vi /etc/php.ini 打开php的安全模式,控制php执行危险函数, 默认是Off,改为On sql.safe_mode = Off 关闭php头部信息, 隐藏版本号, ...