POJ 2991 Crane

题目链接

题意:给定一个垂直的挖掘机臂。有n段,如今每次操作能够旋转一个位置,把[s, s + 1]专程a度,每次旋转后要输出第n个位置的坐标

思路:线段树。把每一段当成一个向量,这样每一段的坐标就等于前几段的坐标和,然后每次旋转的时候,相当于把当前到最后位置所有加上一个角度,这样就须要区间改动了。然后每次还须要查询s,和s + 1当前的角度,所以须要单点查询,这样用线段树去维护就可以

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; const int N = 10005;
const double PI = acos(-1.0); #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) int n, m;
double COS[721], SIN[721]; struct Node {
int l, r, lazy, R;
double x, y;
void gao(int ang) {
R = (R + ang) % 360;
lazy = (lazy + ang) % 360;
double tmpx = x, tmpy = y;
x = COS[ang + 360] * tmpx - SIN[ang + 360] * tmpy;
y = SIN[ang + 360] * tmpx + COS[ang + 360] * tmpy;
}
} node[N * 4]; void pushup(int x) {
node[x].x = node[lson(x)].x + node[rson(x)].x;
node[x].y = node[lson(x)].y + node[rson(x)].y;
} void pushdown(int x) {
if (node[x].lazy) {
node[lson(x)].gao(node[x].lazy);
node[rson(x)].gao(node[x].lazy);
node[x].lazy = 0;
}
} void build(int l, int r, int x = 0) {
node[x].l = l; node[x].r = r; node[x].lazy = node[x].R = 0;
if (l == r) {
double tmp;
scanf("%lf", &tmp);
node[x].x = 0.0;
node[x].y = tmp;
return;
}
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
pushup(x);
} void add(int l, int r, int v, int x = 0) {
if (node[x].l >= l && node[x].r <= r) {
node[x].gao(v);
return;
}
int mid = (node[x].l + node[x].r) / 2;
pushdown(x);
if (l <= mid) add(l, r, v, lson(x));
if (r > mid) add(l, r, v, rson(x));
pushup(x);
} int query(int v, int x = 0) {
if (node[x].l == node[x].r)
return node[x].R;
int mid = (node[x].l + node[x].r) / 2;
int ans = 0;
pushdown(x);
if (v <= mid) ans += query(v, lson(x));
if (v > mid) ans += query(v, rson(x));
pushup(x);
return ans;
} int main() {
int bo = 0;
for (int i = -360; i <= 360; i++) {
COS[i + 360] = cos(i / 180.0 * PI);
SIN[i + 360] = sin(i / 180.0 * PI);
}
while (~scanf("%d%d", &n, &m)) {
if (bo) printf("\n");
else bo = 1;
build(1, n);
int s, a;
while (m--) {
scanf("%d%d", &s, &a);
int a1 = query(s);
int a2 = query(s + 1);
int ang = ((a1 - a2 + a + 180) % 360 + 360) % 360;
add(s + 1, n, ang);
printf("%.2lf %.2lf\n", node[0].x, node[0].y);
}
}
return 0;
}

POJ 2991 Crane(线段树+计算几何)的更多相关文章

  1. [poj 2991]Crane[线段树表示向量之和,而非数量]

    题意: 起重机的机械臂, 由n段组成, 对某一些连接点进行旋转, 询问每次操作后的末端坐标. 思路: 由于旋转会影响到该点之后所有线段的角度, 因此容易想到用线段树记录角度, 成段更新. (但是不是每 ...

  2. POJ 2991 Crane

    线段树+计算几何,区间更新,区间求和,向量旋转. /* *********************************************** Author :Zhou Zhentao Ema ...

  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(线段树)

    Crane Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7687   Accepted: 2075   Special J ...

  7. POJ 2991 Crane (线段树)

    题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...

  8. POJ - 2991 Crane (段树+计算几何)

    Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...

  9. POJ 2991–Crane【线段树+几何】

    题意: 把手臂都各自看成一个向量,则机械手的位置正好是手臂向量之和.旋转某个关节,其实就是把关节到机械手之间的手臂向量统统旋转. 由于手臂很多,要每个向量做相同的旋转操作很费时间.这时就可以想到用线段 ...

随机推荐

  1. mysql basic operation,mysql总结

    mysql> select * from wifi_data where dev_id like "0023-AABBCCCCBBAA" ; 1.显示数据库列表.show d ...

  2. Offer_1

    #include <iostream> #include <cstring> using namespace std; class CMyString { public: CM ...

  3. Bernstein polynomials

    Bernstein多项式能够用来一致逼近闭区间上的连续函数. 对于[0,1]上的连续函数f(x),定义Bernstein多项式 B_n(f,x) = sum{k=0..n} f(k/n)C(k,n)t ...

  4. Cloud Foundry 中国群英会【上海站、成都站】资料宣传

    关注云计算和PaaS层的童鞋可以了解下: http://www.cloudfoundry-heroes-summit.com/shanghai http://www.cloudfoundry-hero ...

  5. 面试中关于Java中涉及到知识点(转)

    本篇文章会对面试中常遇到的Java技术点进行全面深入的总结,帮助我们在面试中更加得心应手,不参加面试的同学也能够借此机会梳理一下自己的知识体系,进行查漏补缺. 1. Java中的原始数据类型都有哪些, ...

  6. debian网易163更新服务器 源

    sudo vi /etc/apt/sources.list 加入如下内容即可: deb http://mirrors.163.com/debian/ jessie main non-free cont ...

  7. Oracle基础知识笔记(10) 约束

    表尽管建立完毕了,可是表中的数据是否合法并不能有所检查,而假设要想针对于表中的数据做一些过滤的话,则能够通过约束完毕,约束的主要功能是保证表中的数据合法性,依照约束的分类,一共同拥有五种约束:非空约束 ...

  8. javascript 交互取值

    var publicClassName; var classIdInMemory = { lastVal: publicClassName, set:function(x){ if(x != &quo ...

  9. Android开发之查看应用包名package和入口activity名称的方法

    使用android自动化测试工具monkeyrunner启动应用时,需要填写被测程序的包名和启动的Activity,以下有两种查看应用包名package和入口activity名称的方法: 方法一:使用 ...

  10. 关键部分CCriticalSection使用

    类CCriticalSection的对象表示一个“临界区”,它是一个用于同步的对象,同一时刻仅仅同意一个线程存取资源或代码区.临界区在控制一次仅仅有一个线程改动数据或其他的控制资源时很实用.比如,在链 ...