csp202309-2坐标变换

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值