【CSP试题回顾】202309-2-坐标变换(其二)
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip> // 导入设置精度所需的库
using namespace std;
struct MyOperate
{
double k;
double theta;
};
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
vector<MyOperate>optList(n + 1);
// 初始化
for (int i = 0; i < n + 1; i++)
{
optList[i].k = 1, optList[i].theta = 0;
}
// 输入操作
for (int i = 1; i <= n; i++)
{
double optFlag, optNum;
cin >> optFlag >> optNum;
// k
if (optFlag==1)
{
optList[i].k = optList[i - 1].k * optNum;
optList[i].theta = optList[i - 1].theta;
}
// theta
else if (optFlag == 2)
{
optList[i].theta = optList[i - 1].theta + optNum;
optList[i].k = optList[i - 1].k;
}
}
// 输入查询
for (int i = 0; i < m; i++)
{
int start, end;
double x, y;
cin >> start >> end >> x >> y;
double kTemp = optList[end].k / optList[start - 1].k;
double thetaTemp = optList[end].theta - optList[start - 1].theta;
double awsX, awsY;
awsX = x * kTemp, awsY = y * kTemp;
double awsX_temp = awsX, awxY_temp = awsY;
awsX = awsX_temp * cos(thetaTemp) - awxY_temp * sin(thetaTemp);
awsY = awsX_temp * sin(thetaTemp) + awxY_temp * cos(thetaTemp);
cout << fixed << setprecision(4);
cout << awsX << " " << awsY << endl;
}
return 0;
}