• [luoguP2129] L国的战斗续之多路出击(模拟 || 矩阵)


    传送门

    1.模拟

    easy

    #include <cstdio>
    #define N 500001
    
    int n, m;
    int X[N], Y[N], x[N], y[N], a = 1, b = 1, p, q;
    char s[N][1];
    
    int main()
    {
        int i;
        scanf("%d %d", &n, &m);
        for(i = 1; i <= n; i++) scanf("%d %d", &X[i], &Y[i]);
        for(i = 1; i <= m; i++)
        {
            scanf("%s", s[i]);
            if(s[i][0] == 'm') scanf("%d %d", &x[i], &y[i]);
        }
        for(i = m; i >= 1; i--)
            if(s[i][0] == 'm')
            {
                p += x[i];
                q += y[i];
            }
            else if(s[i][0] == 'x')
            {
                a *= -1;
                p *= -1;
            }
            else
            {
                b *= -1;
                q *= -1;
            }
        for(i = 1; i <= n; i++) printf("%d %d
    ", X[i] * a + p, Y[i] * b + q);
        return 0;
    }
    

     

    2.矩阵优化

    详见 Matrix67

    #include <cstdio>
    #include <cstring>
    #define N 500001
    
    int n, m;
    int X[N], Y[N], x[N], y[N];
    char s[N][2];
    
    struct Matrix
    {
    	int n, m;
    	int a[11][11];
    	Matrix()
    	{
    		n = m = 0;
    		memset(a, 0, sizeof(a));
    	}
    }sum;
    
    inline Matrix operator * (const Matrix x, const Matrix y)
    {
    	Matrix ret;
    	ret.n = x.n;
    	ret.m = y.m;
    	int i, j, k;
    	for(i = 1; i <= x.n; i++)
    		for(j = 1; j <= y.m; j++)
    			for(k = 1; k <= y.n; k++)
    				ret.a[i][j] += x.a[i][k] * y.a[k][j];
    	return ret;
    }
    
    int main()
    {
    	int i;
    	Matrix t;
    	scanf("%d %d", &n, &m);
    	sum.n = sum.m = 3;
    	sum.a[1][1] = sum.a[2][2] = sum.a[3][3] = 1;
    	for(i = 1; i <= n; i++) scanf("%d %d", &X[i], &Y[i]);
    	for(i = 1; i <= m; i++)
    	{
    		scanf("%s", s[i]);
    		if(s[i][0] == 'm') scanf("%d %d", &x[i], &y[i]);
    	}
    	for(i = m; i >= 1; i--)
    	{
    		memset(t.a, 0, sizeof(t.a));
    		t.n = t.m = 3;
    		t.a[1][1] = t.a[2][2] = t.a[3][3] = 1;
    		if(s[i][0] == 'm') t.a[1][3] = x[i], t.a[2][3] = y[i];
    		if(s[i][0] == 'x') t.a[1][1] = -1;
    		if(s[i][0] == 'y') t.a[2][2] = -1;
    		sum = t * sum;
    	}
    	for(i = 1; i <= n; i++)
    	{
    		memset(t.a, 0, sizeof(t.a));
    		t.n = 3;
    		t.m = t.a[3][1] = 1;
    		t.a[1][1] = X[i];
    		t.a[2][1] = Y[i];
    		t = sum * t;
    		printf("%d %d
    ", t.a[1][1], t.a[2][1]);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    javaWeb普通类获取ApplicationContext
    医学图像处理最全综述
    图像分割最全综述
    解放双手——相机与IMU外参的在线标定
    从零开始一起学习SALM-ICP原理及应用
    SLAM、三维重建,语义相关数据集大全
    SLAM面试常见问题
    SLAM方向国内有哪些优秀公司?
    三维视觉、SLAM方向全球顶尖实验室汇总
    SLAM方向公众号、知乎、博客上有哪些大V可以关注?
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7490415.html
Copyright © 2020-2023  润新知