1. 80分
这里我只使用了基本字符串的操作模拟了题目要求,一般是过不了的啦。注意c++中cin.ignore
的使用。
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
string s[n+1];
cin.ignore();//这玩意,只在cin和getline之间切换的时候使用一次,就一次,一次刚刚好
for(int i=1;i<=n;i++){//因为后续查询的坐标需要的操作不一样,我只能先存下来
getline(cin,s[i]);
//cout<<"s="<<s[i]<<endl;
}
while(m--){
int begin,end;
cin>>begin>>end;
double x,y;
cin>>x>>y;
for(int i=begin;i<=end;i++){
stringstream ss;
ss<<s[i];
int type;
ss>>type;
double k;
ss>>k;
//cout<<"t="<<type<<endl;
//cout<<"k="<<k<<endl;
if(type==1){
x*=k;y*=k;
}
else{
double c=cos(k),s=sin(k);
double xx,yy;
xx=x*c-y*s;yy=x*s+y*c;
x=xx;
y=yy;
}
}
printf("%.3f %.3f\n",x,y);
}
}
2. ac代码
我没想到对于操作可以这样处理!
引用:CCF CSP题解:坐标变换(其二)(202309-2)_csp坐标变换其二-CSDN博客
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<double> xita(100005);
vector<double> k(100005, 1);
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
int type;
double value;
cin >> type >> value;
if (type == 1) {
k[i] = k[i - 1] * value;
xita[i] = xita[i - 1];
} else {
k[i] = k[i - 1];
xita[i] = xita[i - 1] + value;
}
}
for (int i = 0; i < m; ++i) {
int l, r;
double x, y;
cin >> l >> r >> x >> y;
double sum_xita = xita[r] - xita[l - 1];
double pro_k = k[r] / k[l - 1];
cout << fixed << setprecision(3) << (x * cos(sum_xita) - y * sin(sum_xita)) * pro_k << " "
<< (x * sin(sum_xita) + y * cos(sum_xita)) * pro_k << endl;
}
return 0;
}