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. Resource Acquisition Is Initialization(RAII Idiom)

    原文链接:http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Resource_Acquisition_Is_Initialization Intent ...

  2. JavaScript分离代码理解

    window.onload=prepareLinks; //页面加载触发onload事件 function prepareLinks(){ //定义函数 var links=document.getE ...

  3. [Linux] Linux进程PID散列表

    linux系统中每个进程由一个进程id标识,在内核中对应一个task_struct结构的进程描述符,系统中所有进程的task_struct通过链表链接在一起,在内核中,经常需要通过进程id来获取进程描 ...

  4. jQuery判断文本框是否为空

    1.引用jQuery库 <script src="/static/js/jquery_v1.6.1.js" type="text/javascript"& ...

  5. StackOverFlow的2016统计

    http://stackoverflow.com/research/developer-survey-2016

  6. jbpm部署流程定义到MySql报乱码解决方案

    问题起因: 我在使用ant将流程定义和流程相关资源部署到JBPM数据库中的时候,报了下面一个错误. 错误提示,大概是: 11:33:40,781 ERROR JDBCExceptionReporter ...

  7. Android Volley彻底解决(三),定制自己Request

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17612763 经过前面两篇文章的学习,我们已经掌握了Volley各种Request ...

  8. axure扫盲

    axure扫盲 zhuyuansj   2017.10.18 20:39* 字数 162 阅读 25评论 2喜欢 3 编辑文章 坐我旁边的前端今天正好初学axure,然后我就顺便学了几招比较基础的,这 ...

  9. vue.js 跳转同一页面,传不同值,组件监听路由

    watch: { '$route' () { this.type = this.$route.params.type this.loadData() } },

  10. 程序猿(媛)的葵花宝典-- 必备idea 插件plugins 提高编码效率

    最近发现了几个非常好用   提高编码效率 的idea 插件 跟大家分享一下,,,不用谢我!!!!!!!!!!!!! 因为idea自带的插件下载可能连接不上服务器而导致插件下载失败,所以这里推荐使用引入 ...