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., 180 o. 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 903 2
5 5 5
1 270
2 90

Sample Output

5.00 10.00-10.00 5.00
-5.00 10.00

题意:n根相连的木棍初始时竖直摆放,从下到上编号依次为1~n。给出每根木棍长度和c次操作。每次操作两个操作数s和a,表示转动s+1,使得s和s+1夹角变为a,其中夹角指的是s逆时针转到s+1转过的角度。输出每次操作之后最后一根木棍尾端点坐标,其中原点为第一根木棍头端点。

题解:记录第s根棍子到第s+1根棍子间的逆时针角度prv[s],这样每次输入a时就能确定第s+1根及以后棍子的绝对旋转角度,然后用这个角度维护区间值。对于一个向量(x, y),它逆时针旋转A度后,得到的新向量为:x' = xcos(A) - ysin(A),y' = xsin(A) + ycos(A)。

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;const double PI = acos(-1.0);
const int st_size = (1 << 15) - 1;
const int maxn = 10010;//输入
int n, c;
int L[maxn];//线段树维护的数据
double vx[st_size], vy[st_size];    //各节点的向量
double ang[st_size];    //各节点的角度double prv[maxn];//初始化线段树
//k是节点的编号,l, r表示当前节点对应的是[l, r]区间
void init(int k, int l, int r)
{ang[k] = vx[k] = 0.0;if (r - l == 1)     //叶子节点vy[k] = L[l];else    //非叶子节点{int chl = k * 2 + 1, chr = k * 2 + 2;init(chl, l, (l+r)/2);init(chr, (l+r)/2, 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;if (s < r){int chl = v * 2 + 1, chr = v * 2 + 2;int m = (l + r) / 2;change(s, a, chl, l, m);change(s, a, chr, m, r);if (s <= m)ang[v] += a;double si = sin(ang[v]), co = cos(ang[v]);vx[v] = vx[chl] + co * vx[chr] - si * vy[chr];vy[v] = vy[chl] + si * vx[chr] + co * vy[chr];}
}int main()
{int cnt = 0;while (~scanf("%d%d", &n, &c)){if (cnt++)printf("\n");for (int i = 0; i < n; ++i)scanf("%d", &L[i]);//初始化init(0, 0, n);fill(prv+1, prv+n, PI);while (c--){int s;double a;scanf("%d%lf", &s, &a);a = a / 180.0 * PI;   //把角度换算成弧度change(s, a-prv[s], 0, 0, n);prv[s] = a;printf("%.2f %.2f\n", vx[0], vy[0]);}}return 0;
}

poj2991(Crane)线段树+计算几何相关推荐

  1. POJ 2991 Crane(线段树+计算几何)

    POJ 2991 Crane 题目链接 题意:给定一个垂直的挖掘机臂.有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标 思路:线段树.把每一段当成 ...

  2. 数据结构---线段树

    线段树 转载请注明出处,谢谢!http://blog.csdn.net/metalseed/article/details/8039326  持续更新中···   一:线段树基本概念 1:概述 线段树 ...

  3. 【转】线段树题目 汇总 讲解(by not only success)

    转载自:http://www.notonlysuccess.com/ 非常喜欢他的代码风格以及简洁的思路,感谢notonlysuccess! PS:他的个人网站好像是上不去了-.- 线段树 很早前写的 ...

  4. ACM大牛总结的线段树专辑

    https://blog.csdn.net/qq_25605637/article/details/46967529 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章 ...

  5. 【转载】完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...

  6. 转载自杭电大牛的博客 线段树 绝对经典

    转载自:http://www.notonlysuccess.com/ 不可不看的经典 学线段树必看,大牛很多,给后人留下记录的却没有几个,谢谢这位大牛~! 因为我这最近他博客打不开了...特意从别人那 ...

  7. 线段树模板(来自胡浩大牛)

    http://www.notonlysuccess.com/(今天看二叉树,想回来看看,发现大牛博客进不去...) 如果要学,就要好好学.我copy的,如有错,请看http://www.cnblogs ...

  8. 线段树开新坑:kuangbin带你飞

    写在最前面的废话 这里I以前的题是暑假刚刚开始的时候在家写的,然后多校一波就荒废了 9月开头回家一波,重新填坑,= =,kuangbin带你飞的pdf,这才一半题,后面还有一波,蓝瘦,慢慢写吧,不写题 ...

  9. 大牛整理的线段树集锦

     转载自:http://www.notonlysuccess.com/ 膜拜之... [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pk ...

  10. ACM_大牛总结的线段树专辑

    附上原出处:http://blog.csdn.net/qq_25605637/article/details/46967529 [完全版]线段树 这是从大牛那里粘过来的总结,对于刚训练线段树的我来说帮 ...

最新文章

  1. MPB:湖南师大尹佳组-​乳酸菌益生菌表面粘附能力的检测
  2. Topcoder Srm 671 Div2 1000 BearDestroysDiv2
  3. 小学计算机试教教案,小学信息技术人教版三年级下册第7课《轻轻松松来上网》优质课公开课教案教师资格证面试试讲教案...
  4. 推荐系统炼丹笔记:Embedding在内存问题上的一种解法
  5. LeetCode----9. 回文数
  6. 使用G1后报错-CircuitBreakingException: [parent] Data too large
  7. java 反射 框架_Java 反射,开发框架必备技能
  8. linkedhashset_Java LinkedHashSet contains()方法与示例
  9. SpringBoot2.0 基础案例(12):基于转账案例,演示事务管理操作
  10. Intellij IDEA IDE 运行Sphinx-4 DEMO helloworld出现空...
  11. Excel中的fixed函数
  12. day18 8.jdbc中设置事务隔离级别
  13. nice和renice命令详解
  14. 《电子商务安全》考试重点/学习重点
  15. natapp 使用教程
  16. 计算机类中英附录,欧盟gmp附录11-计算机系统(中英文对照)-20210410004737.docx-原创力文档...
  17. ckplayer 播放视频
  18. C#与PLC通信开发之三菱FX系列PLC
  19. 前端工程化——脚手架及自动化构建
  20. JVM 内存模型面试题目

热门文章

  1. 一、tkinter简介
  2. Expert C Programming学习笔记(1)
  3. 浅谈前后端分离与实践 之 nodejs 中间层服务
  4. Cookie 版购物车
  5. div+css命名大全
  6. Marlin 溫度感應器 數值轉換對應表
  7. jQuery 插件设置cookie
  8. pbs 作业管理命令
  9. chromium中的性能优化工具syzyProf
  10. python学习之re库