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.
poj2991 Crane(线段树)的更多相关文章
- poj2991 Crane(线段树+集合)白书例题
题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现, ...
- 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【线段树+几何】
题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...
- Crane /// 向量旋转+线段树
题目大意: 给定n条首尾相接的线段的长度 第一条从0,0开始,所有线段垂直与x轴向上延伸 给定c次操作 每次操作给定 s,a 使得 由第s条线段的角度 逆时针旋转a后 达到第s+1条线段的角度 每次操 ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
随机推荐
- kubernetes 生命周期问题分析
1.Failed -- pod里至少一个容器以非0code退出,说明应用有问题,需要debug应用容器 2.pending -- 说明API对象已经被创建和保存在etcd数据库里,但是创建过程出了问 ...
- golang 文件服务器
在go语言中可以用一句代码做一个文件服务器.如果有很多文件需要通过网页来供其他人下载,可以使用这个方法. package main import ( "log" "net ...
- drupal 7 连接多个数据库
Drupal7系统,重写了数据库操作内核,其强大的功能无需多言.一次偶然的机会,需要提取Drupal默认安装数据库之外的一个数据库中的数据 ,可谓是绞尽脑汁,上网查阅最后终于找到了一个笨而又合适的方法 ...
- js倒计时,页面刷新时,不会从头计时
最近不忙,瞎鼓捣...哈哈 这里利用了H5的本地存储 localStorage,取秒数直接用了php的time()方法,就懒得用js取了. 把第一次访问页面时的时间存在客户端,然后再刷新的时候,比较用 ...
- 20155202张旭《网络对抗技术》 week1 PC平台逆向破解及Bof基础实践
20155202张旭<网络对抗技术> week1 PC平台逆向破解及Bof基础实践 1.实践目标: 实践对象:一个名为pwn1的linux可执行文件. 该程序正常执行流程是: main调用 ...
- cmake源码包安装后的卸载问题
cmake源码包安装 CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程),具体学习请移步官网CMake 本文介绍的就是用cmake去安装的别人的包. 一般流程: ...
- 利用RMAN转移裸设备到文件系统
本文只是为了个人备忘. 参考eagyle的:http://www.eygle.com/archives/2005/12/oracle_howto_move_datafile_raw.html 我首先挂 ...
- 如何写论文的introduction
重要的是写Introduction.写Introduction就和写童话一样.(转自知乎珵cici) 1. 有一条巨龙抓走了公主 (介绍你的问题为什么值得研究) 2. 巨龙是多么多么多么难打(强调你的 ...
- C语言学习之联合类型
前言 联合(union)是一种特殊的数据类型,和结构体很像,结构体各成员变量有自己独立的存储位置,而联合的成员变量共享同一片存储区域,因此联合变量再一个时刻只能保存它的某一个成员的值. 联合的定义和初 ...
- 基于vue全家桶制作的移动端音乐WebApp
Vue.js 2.0实战项目 基于Vue + Vuex + Vue-router + Webpack 2.0 打造移动端音乐WebAPP,实现了轮播图.音乐推荐.歌手列表.音乐搜索.注册等功能. 技术 ...