传送门:
http://codeforces.com/problemset/problem/618/E
题意:
n条线段初始都位于x轴,长度都相等,现在有2种操作,第一种是把某个线段拉长,第二种是把某个线段及其以后的线段全部相对于上一条线段旋转一定的角度,问每次操作执行后,最后一个点的坐标!
#include<bits/stdc++.h>
using namespace std;
#define pi 2 * acos(0.)
int n, m;
const int N = 333333;
double sx[N << 2], sy[N << 2], sa[N << 2];
void upd(int v, int l, int r, int pos, int dx, double da) {
if (l + 1 == r) {
double R = sqrt(sx[v] * sx[v] + sy[v] * sy[v]);
double A = atan2(sy[v], sx[v]);
R += dx;
A += da;
sx[v] = R * cos(A);
sy[v] = R * sin(A);
sa[v] = A;
return;
}
int mid = (l + r + 1) / 2;
if (pos < mid) upd(2 * v + 1, l, mid, pos, dx, da);
else upd(2 * v + 2, mid, r, pos, dx, da);
double R = sqrt(sx[2 * v + 2] * sx[2 * v + 2] + sy[2 * v + 2] * sy[2 * v + 2]);
double A = atan2(sy[2 * v + 2], sx[2 * v + 2]);
sx[v] = sx[2 * v + 1] + R * cos(A + sa[2 * v + 1]);
sy[v] = sy[2 * v + 1] + R * sin(A + sa[2 * v + 1]);
sa[v] = sa[2 * v + 1] + sa[2 * v + 2];
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i) {
upd(0, 0, n, i, 1, 0);
}
while(m--) {
int tp, num, add;
scanf("%d%d%d", &tp, &num, &add);
if (tp == 1) {
upd(0, 0, n, num - 1, add, 0);
} else {
upd(0, 0, n, num - 1, 0, 2 * pi - add / 360. * 2. * pi);
}
printf("%0.9lf %0.9lf\n", sx[0], sy[0]);
}
}