标签:des style os io for art 问题 ar
Description
Input
Output
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
题意:有一个n节的机械手,每次让某个节点移动使得第i条边和第i+1条边的夹角是a,初始化夹角都是180度,求经过操作后最后一个节点位置
思路:同样是线段树的区间更新,因为要求的是最后一个点的坐标,我们知道向量是可以相加的,那么我们把每个线段当成向量相加的话,就可以得到最后的坐标了,再者就是旋转的问题了,我们同样知道旋转后,第i+1后的边都会受到影响,这就是线段树的区间更新了;然后有了逆时针向量旋转的公式我们就可以得到解了,注意的地方是:我们每次储存上一次的角度,依次来推出这次需要旋转的角度,还有就是不知道会平白无故W了还多次,还是换个姿势做的
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define lson(x) ((x) << 1)
#define rson(x) ((x) << 1 | 1)
using namespace std;
const int maxn = 10002;
int angle[maxn], setv[maxn<<2];
double sumx[maxn<<2], sumy[maxn<<2];
void update(int pos) {
sumx[pos] = sumx[lson(pos)] + sumx[rson(pos)];
sumy[pos] = sumy[lson(pos)] + sumy[rson(pos)];
}
void build(int l, int r, int pos) {
setv[pos] = 0;
if (l == r) {
scanf("%lf", &sumy[pos]);
sumx[pos] = 0;
return;
}
int m = l + r >> 1;
build(l, m, lson(pos));
build(m+1, r, rson(pos));
update(pos);
}
void change(int pos, int d) {
double tmp = d * acos(-1.0) / 180;
double x = sumx[pos]*cos(tmp) - sumy[pos]*sin(tmp);
double y = sumx[pos]*sin(tmp) + sumy[pos]*cos(tmp);
sumx[pos] = x;
sumy[pos] = y;
}
void push(int pos) {
if (setv[pos]) {
setv[lson(pos)] += setv[pos];
setv[rson(pos)] += setv[pos];
change(lson(pos), setv[pos]);
change(rson(pos), setv[pos]);
setv[pos] = 0;
}
}
void modify(int l, int r, int pos, int x, int y, int z) {
if (x <= l && y >= r) {
setv[pos] += z;
change(pos, z);
return;
}
push(pos);
int m = l + r >> 1;
if (x <= m)
modify(l, m, lson(pos), x, y, z);
if (y > m)
modify(m+1, r, rson(pos), x, y, z);
update(pos);
}
int main() {
int n, q;
int first = 1;
while (scanf("%d%d", &n, &q) != EOF) {
if (first)
first = 0;
else printf("\n");
build(1, n, 1);
for (int i = 1; i <= n; i++)
angle[i] = 180;
int a, b;
while (q--) {
scanf("%d%d", &a, &b);
modify(1, n, 1, a+1, n, b-angle[a]);
angle[a] = b;
printf("%.2lf %.2lf\n", sumx[1], sumy[1]);
}
}
return 0;
}POJ - 2991 Crane (线段树+计算几何),布布扣,bubuko.com
标签:des style os io for art 问题 ar
原文地址:http://blog.csdn.net/u011345136/article/details/38370039