记录编号 357746 评测结果 AAAAAAAAAA
题目名称 [SYOI 2015] Asm.Def的命令 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 12.157 s
提交时间 2016-12-12 13:54:28 内存使用 1.82 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>

using namespace std;

class Matrix
{
public:
	double a[4][4];
	int row, col;
	Matrix()
	{
		
	}
	Matrix(int r, int c)
	{
		row = r;
		col = c;
	}
	void copy(Matrix &o)
	{
		memcpy(a, o.a, sizeof(a));
	}
	void stdmatrix()
	{
		memset(a, 0, sizeof(a));
		for(int i = 1; i < 4; i++)
			a[i][i] = 1;
	}
	Matrix mul(Matrix &o)
	{
		Matrix r(row, o.col);
		for(int i = 1; i <= r.row; i++)
		{
			for(int j = 1; j <= r.col; j++)
			{
				r.a[i][j] = 0.0;
				for(int k = 1; k <= o.row; k++)
					r.a[i][j] += a[i][k] * o.a[k][j]; 
			}
		}
		return r;
	}
	void out()
	{
		printf("\n*--------------------------------\n");
		for(int i = 1; i <= row; i++)
		{
			for(int j = 1; j <= col; j++)
				printf("%.1lf ", a[i][j]);
			putchar('\n');
		}
		printf("*--------------------------------\n");
	}
};

const int MAXN = 1e5+2;
/*
struct node
{
	int ls, rs;
	int l, r;
	bool lazy;
	Matrix v;
	Matrix tag;
}ns[MAXN << 1];
int root = 1;
int last = root;
int build(int l, int r)
{
	int cur = last++;
	node &d = ns[cur];
	d.l = l;
	d.r = r;
	d.lazy = false;
	
	d.tag.row = 3;
	d.tag.col = 3;
	memset(d.tag.a, 0, sizeof(d.tag.a));
	d.tag.stdmatrix();
	d.v.row = 3;
	d.v.col = 1;
	memset(d.v.a, 0, sizeof(d.v.a));
	d.v.a[2][1] = (double)l; 
	
	if(l == r)
		return cur;
	
	int mid = (l+r)>>1;
	if(l <= mid)
	{
		d.ls = build(l, mid);
		d.rs = build(mid+1, r);
		return cur;
	}
	return 0;
}
Matrix updata(3, 3);    //更新的内容
void pushdown(int c)
{
	node &d = ns[c];
	if(d.lazy)
	{
		ns[d.ls].tag = d.tag; 
		ns[d.ls].lazy = true;
		ns[d.rs].tag = d.tag;
		ns[d.rs].lazy = true;
		d.v = d.tag.mul(d.v);
		d.tag.stdmatrix();
		d.lazy = false;
	}
}
void update(int c, int l, int r)
{
	if(!c)return;
	if(ns[c].l == l && ns[c].r == r)
	{
		if(l != r)
			ns[c].lazy = true;
		ns[c].tag = updata.mul(ns[c].tag);
		return;
	}else
	{
		pushdown(c);
		node &d = ns[c];
		if(r <= ns[d.ls].r)
			update(d.ls, l, r);
		else if(l >= ns[d.rs].l)
			update(d.rs, l, r);
		else
		{
			update(d.ls, l, ns[d.ls].r);
			update(d.rs, ns[d.rs].l, r);
		}
	}

}

Matrix& query(int c, int pos)
{
	pushdown(c);
	if(ns[c].l == pos && ns[c].r == pos)
	{
		return ns[c].v;
	}
	node &d = ns[c];
	if(d.ls && pos <= ns[d.ls].r)
		return query(d.ls, pos);
	else if(d.rs && pos >= ns[d.rs].l)
		return query(d.rs, pos);
}

Matrix updata(3, 3);    //更新的内容
Matrix poses[MAXN];
*/
double x[MAXN], y[MAXN];
const double pi = acos(-1);
void init(int n)
{
	for(int i = 1; i <= n; i++)
	{
		y[i] = (double)i;
	}
}
void update1(int l, int r, double dx, double dy)
{
	for(int i = l; i <= r; i++)
	{
		x[i] += dx;
		y[i] += dy;
	}
}
void update2(int l, int r, int deg)
{
	double c = cos(pi*deg/180);
	double s = sin(pi*deg/180);
	for(int i = l; i <= r; i++)
	{
		double ox = x[i];
		double oy = y[i];
		x[i] = c*ox-s*oy;
		y[i] = s*ox+c*oy;
	}
}

int main()
{
	freopen("asm_command.in", "r", stdin);
	freopen("asm_command.out", "w", stdout);
	int n, q;
	scanf("%d %d", &n, &q);
	init(n);
	while(q--)
	{
		int op;
		int a1,a2,a3,a4;
		scanf("%d", &op);
		switch(op)
		{
			case 0:
			{
				scanf("%d", &a1);
	
				printf("%.1lf %.1lf\n", x[a1], y[a1]);
				break;
			}
			case 1:
				scanf("%d %d %d %d", &a1, &a2, &a3, &a4);
				/*
				memset(updata.a, 0, sizeof(updata.a));
				updata.a[1][1] = 1.0;
				updata.a[1][3] = (double)a3;
				updata.a[2][2] = 1.0;
				updata.a[2][3] = (double)a4;
				updata.a[3][3] = 1.0;
				*/
				/*
				 _      _      _   _        _       _
				|        |    |     |      |         | 
				| 1 0 dx |    |  x  |      |   x+dx  |
				| 0 1 dy |  × |  y  |   =  |   y+dy  |
				| 0 0 1  |    |  1  |      |    1    |
				|_      _|    |_   _|      |_       _|
				*/
				update1(a1, a2, a3, a4);
				break;
			case 2:
				scanf("%d %d %d", &a1, &a2, &a3);
				/*
  				 _               _      _   _        _              _
				|                 |    |     |      |                |
				| cosa  -sina   0 |    |  x  |      |   cosax-sinay  |
				| sina  cosa    0 |  × |  y  |  =   |   sinax+cosay  |
				| 0       0     1 |    |  1  |      |        1       |
				|_               _|    |_   _|      |_              _|
				
				*/
				/*
				memset(updata.a, 0, sizeof(updata.a));
				updata.a[1][1] = cos(pi*a3/180.0);
				updata.a[1][2] = -sin(pi*a3/180.0);
				updata.a[2][1] = -updata.a[1][2];
				updata.a[2][2] = updata.a[1][1];
				updata.a[3][3] = 1.0;
				*/
				update2(a1, a2, a3);
				break;
		}
	}
	return 0;
}