mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-24 02:28:47 +00:00
75 lines
1.7 KiB (Stored with Git LFS)
C++
75 lines
1.7 KiB (Stored with Git LFS)
C++
#include <bits/stdc++.h>
|
|
#include "testlib.h"
|
|
using namespace std;
|
|
|
|
int a[5];
|
|
struct Matrix {
|
|
int a[5][5];
|
|
Matrix() {memset(a, 0, sizeof a);}
|
|
friend Matrix operator * (Matrix A, Matrix B) {
|
|
Matrix C;
|
|
for (int i = 1; i <= 2; ++ i) {
|
|
for (int j = 1; j <= 2; ++ j) {
|
|
for (int k = 1; k <= 2; ++ k) {
|
|
C.a[i][j] += A.a[i][k] * B.a[k][j];
|
|
}
|
|
}
|
|
}
|
|
return C;
|
|
}
|
|
} A, B, _A, _B, Ans;
|
|
|
|
void init() {
|
|
A.a[1][1] = 1; A.a[1][2] = 1; A.a[2][1] = 0; A.a[2][2] = 1;
|
|
B.a[1][1] = 0; B.a[1][2] = 1; B.a[2][1] = -1; B.a[2][2] = 0;
|
|
_A.a[1][1] = 1; _A.a[1][2] = -1; _A.a[2][1] = 0; _A.a[2][2] = 1;
|
|
_B.a[1][1] = 0; _B.a[1][2] = -1; _B.a[2][1] = 1; _B.a[2][2] = 0;
|
|
}
|
|
|
|
bool chk() {
|
|
if (Ans.a[1][1] != a[1]) return false;
|
|
if (Ans.a[1][2] != a[2]) return false;
|
|
if (Ans.a[2][1] != a[3]) return false;
|
|
if (Ans.a[2][2] != a[4]) return false;
|
|
return true;
|
|
}
|
|
|
|
int main(int argc, char** argv){
|
|
registerTestlibCmd(argc, argv);
|
|
init();
|
|
int T = inf.readInt();
|
|
while (T --) {
|
|
for (int i = 1; i <= 4; ++ i) a[i] = inf.readInt();
|
|
int n = ouf.readInt();
|
|
Ans.a[1][1] = 1; Ans.a[1][2] = 0;
|
|
Ans.a[2][2] = 1; Ans.a[2][1] = 0;
|
|
for (int i = 1; i <= n; ++ i) {
|
|
string s = ouf.readToken();
|
|
int x = ouf.readInt();
|
|
if (x > 0) {
|
|
if (s == "A") {
|
|
for (int j = 1; j <= x; ++ j) Ans = Ans * A;
|
|
}
|
|
else {
|
|
for (int j = 1; j <= x; ++ j) Ans = Ans * B;
|
|
}
|
|
}
|
|
else {
|
|
if (s == "A") {
|
|
for (int j = 1; j <= -x; ++ j) Ans = Ans * _A;
|
|
}
|
|
else {
|
|
for (int j = 1; j <= -x; ++ j) Ans = Ans * _B;
|
|
}
|
|
}
|
|
}
|
|
// cerr<< "OK!!!" << endl;
|
|
if (chk() == false) {
|
|
quitf(_wa,"your answer is wrong, %d",114514);
|
|
}
|
|
else void();
|
|
}
|
|
quitf(_ok, "your answer is beautiful %d", 1919810);
|
|
return 0;
|
|
}
|