202309-2 坐标变换(其二)

80分暴力:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m;
struct point
{ // 存操作
	int flag;
	double ee;
} pp[maxn];
int main()
{
	cin >> n >> m;
	for (int u = 1; u <= n; u++) // 存操作
	{
		int op;
		cin >> op;
		if (op == 1)
		{
			pp[u].flag = 1;
			cin >> pp[u].ee;
		}
		else if (op == 2)
		{
			pp[u].flag = 2;
			cin >> pp[u].ee;
		}
	}
	for (int t = 0; t < m; t++)
	{
		int i, j;
		double x, y;
		cin >> i >> j ;
		scanf("%lf %lf", &x,&y);
		for (int u = i; u <= j; u++)
		{
			if (pp[u].flag == 1)
			{
				x = x * pp[u].ee;
				y = y * pp[u].ee;
			}
			else if (pp[u].flag == 2)
			{
				double tx, ty;
				tx = x * cos(pp[u].ee) - y * sin(pp[u].ee);
				ty = x * sin(pp[u].ee) + y * cos(pp[u].ee);
				x=tx,y=ty;
			}
		}
		printf("%.3f %.3f\n", x, y);
	}
}

100分前缀和思想:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m;
double k[maxn], e[maxn]; // 存前缀
/*只考虑存在拉伸操作的情况下,最终拉伸的系数等于每次拉伸操作系数的乘积。
只考虑存在旋转操作的情况下,最终旋转的角度等于每次旋转操作角度的和。*/
int main()
{
	cin >> n >> m;
	k[0] = 1;
	e[0] = 0;
	for (int u = 1; u <= n; u++) // 存前缀
	{
		int op;
		cin >> op;
		if (op == 1)
		{
			double kk;
			cin >> kk;
			k[u] = k[u - 1] * kk;
			e[u] = e[u - 1];
		}
		else if (op == 2)
		{
			double ee;
			cin >> ee;
			k[u] = k[u - 1];
			e[u] = e[u - 1] + ee;
		}
	}
	for (int t = 0; t < m; t++)
	{
		int i, j;
		double x, y;
		cin >> i >> j;
		scanf("%lf %lf", &x, &y);
		double kk = k[j] / k[i-1]; // 拉伸
		double ee = e[j] - e[i-1]; // 旋转
		double ax, ay, bx, by;
		ax = x * kk;
		ay = y * kk;
		bx = ax * cos(ee) - ay * sin(ee);
		by = ax * sin(ee) + ay * cos(ee);
		printf("%.3f %.3f\n", bx, by);
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值