CCF-CSP认证 2023年9月02 坐标变换(二)

题解:需要将所有的前n次变换存储到对应的数组里,在第i-j次变换就直接数组相减即可。

//  #pragma GCC optimize(2, 3, "Ofast", "inline")
#include <bits/stdc++.h>
// #define endl '\n'
using namespace std;
double k[100010];
double theta[100010];
void work()
{
    int n,m;
    scanf("%d%d",&n,&m);
    memset(k,1,sizeof(k));
    k[0]=1;
    theta[0]=0;
    int type;
    double oper;
    for(int i=1;i<=n;i++)
    {
        scanf("%d,%lf",&type,&oper);
        if(type==1)
        {
            k[i]=k[i-1]*oper;
            theta[i]=theta[i-1];
        }
        else
        {
            k[i]=k[i-1];
            theta[i]=theta[i-1]+oper;
        }
    }
    int i,j;
    double x,y;
    double deltak;
    double deltatheta;
    for(int q=0;q<m;q++)
    {
        scanf("%d %d %lf %lf",&i,&j,&x,&y);
        deltak=k[j]/k[i-1];
        deltatheta=theta[j]-theta[i-1];
        double x1=x*deltak;
        double y1=y*deltak;
        x=x1*cos(deltatheta)-y1*sin(deltatheta);
        y=x1*sin(deltatheta)+y1*cos(deltatheta);
        // cout<<x<<" "<<y<<endl;
        printf("%.3f %.3f\n",x,y);
    }
}
int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    work();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值