本文主要是介绍【CSP试题回顾】202309-2-坐标变换(其二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
}
这篇关于【CSP试题回顾】202309-2-坐标变换(其二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!