80分暴力:
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m; struct point { // 存操作 int flag; double ee; } pp[maxn]; int main() { cin >> n >> m; for (int u = 1; u <= n; u++) // 存操作 { int op; cin >> op; if (op == 1) { pp[u].flag = 1; cin >> pp[u].ee; } else if (op == 2) { pp[u].flag = 2; cin >> pp[u].ee; } } for (int t = 0; t < m; t++) { int i, j; double x, y; cin >> i >> j ; scanf("%lf %lf", &x,&y); for (int u = i; u <= j; u++) { if (pp[u].flag == 1) { x = x * pp[u].ee; y = y * pp[u].ee; } else if (pp[u].flag == 2) { double tx, ty; tx = x * cos(pp[u].ee) - y * sin(pp[u].ee); ty = x * sin(pp[u].ee) + y * cos(pp[u].ee); x=tx,y=ty; } } printf("%.3f %.3f\n", x, y); } }
100分前缀和思想:
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m; double k[maxn], e[maxn]; // 存前缀 /*只考虑存在拉伸操作的情况下,最终拉伸的系数等于每次拉伸操作系数的乘积。 只考虑存在旋转操作的情况下,最终旋转的角度等于每次旋转操作角度的和。*/ int main() { cin >> n >> m; k[0] = 1; e[0] = 0; for (int u = 1; u <= n; u++) // 存前缀 { int op; cin >> op; if (op == 1) { double kk; cin >> kk; k[u] = k[u - 1] * kk; e[u] = e[u - 1]; } else if (op == 2) { double ee; cin >> ee; k[u] = k[u - 1]; e[u] = e[u - 1] + ee; } } for (int t = 0; t < m; t++) { int i, j; double x, y; cin >> i >> j; scanf("%lf %lf", &x, &y); double kk = k[j] / k[i-1]; // 拉伸 double ee = e[j] - e[i-1]; // 旋转 double ax, ay, bx, by; ax = x * kk; ay = y * kk; bx = ax * cos(ee) - ay * sin(ee); by = ax * sin(ee) + ay * cos(ee); printf("%.3f %.3f\n", bx, by); } }