CSP-202309-2-坐标变换(其二)
解题代码
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
struct MyOpt
{
double k, theta;
};
int n, m, opt, s, e;
double para, x, y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
vector<MyOpt>OptList(n + 1, { 1,0 });
for (size_t i = 1; i <= n; i++)
{
cin >> opt >> para;
if (opt == 1)
{
OptList[i].k *= OptList[i - 1].k * para;
OptList[i].theta = OptList[i - 1].theta;
}
else if (opt == 2)
{
OptList[i].k = OptList[i - 1].k;
OptList[i].theta += OptList[i - 1].theta + para;
}
}
for (size_t i = 0; i < m; i++)
{
cin >> s >> e >> x >> y;
x *= (OptList[e].k / OptList[s - 1].k), y *= (OptList[e].k / OptList[s - 1].k);
double xx = x, yy = y;
x = xx * cos(OptList[e].theta - OptList[s - 1].theta) - y * sin(OptList[e].theta - OptList[s - 1].theta);
y = xx * sin(OptList[e].theta - OptList[s - 1].theta) + y * cos(OptList[e].theta - OptList[s - 1].theta);
cout << fixed << setprecision(3) << x << " " << y << endl;
}
return 0;
}