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.

最新文章

  1. Eclipse 常用快捷键 (动画讲解)
  2. WebService返回DataTable
  3. 报错问题:InnoDB: Error: log file ./ib_logfile0 is of different size
  4. Scrum4.0+5.0
  5. 开发ERP软件应该遵守的22条规则
  6. C# 中 KeyPress 、KeyDown 和KeyPress的详细区别[转]
  7. wooyun本地数据抓取
  8. Linux基础:软件安装(rpm,yum,源代码)
  9. ajax异步文件上传,iframe方式
  10. POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)(转)
  11. Python Tips and Traps(一)
  12. 使用Log4net记录日志
  13. CenOS 6.5下 mysql自动备份
  14. JSP中EL很常用,怎样使用大于号、小于号、等于号等
  15. 使用yield生成器,用Python实现用户对用户输入信息的监听和过滤
  16. angular ztree 梯形结构json配置、点击节点事件、默认展开所有
  17. Myeclipse--jBPM4.3插件
  18. vue将表格导出为excel
  19. 基于虹软 2.0 人脸识别猜年龄 java版 demo
  20. 《编写可维护的javascript》读书笔记(上)

热门文章

  1. 01-Maven功能特点
  2. jpbm工作流框架
  3. Scala学习(一)练习
  4. [LOJ#2878]. 「JOISC 2014 Day2」邮戳拉力赛[括号序列dp]
  5. storm从入门到放弃(三),放弃使用 StreamId 特性
  6. Java中Class类详解、用法及泛化
  7. JQ_返回顶部
  8. Category Theory: 01 One Structured Family of Structures
  9. 记录Appium-desktop踩过的坑could not find devices
  10. openssl证书及配置