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. 建造者模式(Builder和Director)

    一.建造者模式介绍 建造者模式:将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示. [构建与表示分离,同构建不同表示] 假如一个对象的构建很复杂,需要很多步骤.则可以使用建造者模式 ...

  2. vux配置i18n

    根据使用文档,先引入i18n import VueI18n from 'vue-i18n'; Vue.use(VueI18n) const i18n = new VueI18n({ locale: ' ...

  3. Python3的第一个程序(三)

    现在,了解了如何启动和退出Python的交互式环境,我们就可以正式开始编写Python代码了. 在写代码之前,请千万不要用“复制”-“粘贴”把代码从页面粘贴到你自己的电脑上.写程序也讲究一个感觉,你需 ...

  4. New Concept English three(15)

    31w/m 43 Children always appreciate small gifts of money. Father, of course, provides a regular supp ...

  5. 微信小程序之答题领券系统构建

    这个项目做了有一段时间了,客户需求反复更改,所以版本也是在不断迭代,下面简要说明一下这个系统的构建过程吧 系统功能: 1.基于商城系统开发的商品答题领券功能 2.首页商品列表页显示当前商品的答题状态 ...

  6. Springboot yml获取系统环境变量的值

    注意,这里说的是获取系统环境变量的值,譬如Windows里配置的JAVA_HOME之类的,可以直接在Springboot的配置文件中获取. 我们经常使用一些docker管理平台,如DaoCloud.r ...

  7. 关于Objective-C 2.0 的垃圾收集

      Objective-C 2.0最大的增强可能就是垃圾收集了(Garbage Collection).与“垃圾收集”对应的是传统的引用计数(Reference Count)内存管理形式. 使用了垃圾 ...

  8. linux 文件上传&软件安装(rpm)

    文件的上传与下载(linux -linux ) 实例1:从远处复制文件到本地目录命令:scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz /o ...

  9. 一个导出redis有序集合sorted-sets的shell脚本

    通过keys匹配需要导出的有序集合名称,这些集合命名格式为:*_010_09/Dec/2015 依次通过zscan导出有序集合中的数据,并分别保存 #/bin/shzset_pattern=”*_01 ...

  10. eclipse显示/隐藏代码行号

    Window→Preferences→General→Editors→TextEditors→勾选Show line numbers