poj2991 Crane(线段树)
Description
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 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 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
题解:
我是没想到是线段树,看了是线段树后自己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.
最新文章
- Eclipse 常用快捷键 (动画讲解)
- WebService返回DataTable
- 报错问题:InnoDB: Error: log file ./ib_logfile0 is of different size
- Scrum4.0+5.0
- 开发ERP软件应该遵守的22条规则
- C# 中 KeyPress 、KeyDown 和KeyPress的详细区别[转]
- wooyun本地数据抓取
- Linux基础:软件安装(rpm,yum,源代码)
- ajax异步文件上传,iframe方式
- POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)(转)
- Python Tips and Traps(一)
- 使用Log4net记录日志
- CenOS 6.5下 mysql自动备份
- JSP中EL很常用,怎样使用大于号、小于号、等于号等
- 使用yield生成器,用Python实现用户对用户输入信息的监听和过滤
- angular ztree 梯形结构json配置、点击节点事件、默认展开所有
- Myeclipse--jBPM4.3插件
- vue将表格导出为excel
- 基于虹软 2.0 人脸识别猜年龄 java版 demo
- 《编写可维护的javascript》读书笔记(上)
热门文章
- 01-Maven功能特点
- jpbm工作流框架
- Scala学习(一)练习
- [LOJ#2878]. 「JOISC 2014 Day2」邮戳拉力赛[括号序列dp]
- storm从入门到放弃(三),放弃使用 StreamId 特性
- Java中Class类详解、用法及泛化
- JQ_返回顶部
- Category Theory: 01 One Structured Family of Structures
- 记录Appium-desktop踩过的坑could not find devices
- openssl证书及配置