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