1346 recursive base time limit: 1 second space limit: 131072 KB score: 80 Difficulty: 5-level algorithm topic collection attention
function f (n,m)
{
If N=1 or M=1 returns to A[n][m];
Returns f (N-1,m) Xor F (n,m-1);
}
Read in 2<=n,m<=100
For i=2->100 read in A[1][i]
For i=2->100 read in a[i][1]
Output f (n,m)
It is found that the program becomes unusually slow when the n,m is larger.
Small B After some thinking, soon solved the problem.
At this time small C appeared, I will n,m all increase 131072, you still can solve?
In contrast, I will read all the a[1][i] and a[i][1 in 2->131172).
Small b made a difficult, so come to you, can you help him?
Input
The first line reads in 131,171 positive integers, representing i=2->131172 's a[1][i] (1<=a[1][i]<=1000000000). The second line reads in 131,171 positive integers, representing i=2->131172 's a[i][1] (1<=a[i][1]<=1000000000). The third line reads a positive integer, Q (1<=q<=10000), indicating the number of queries. The next Q line, two numbers per line n,m (2<=n,m<=100), represents each group of queries.
Output
Q Line, per action F (n+131072,m+131072)
Input example
2 3 4 5 6 7 8 ... 131171 1311722 3 4 5 6 7 8 ... 131171 13117232 22) 32 4
Output example
00131072
A[i][j]=a[i-1][j]^a[i][j-1]=a[i-2][j]^a[i-1][j-1]^a[i-1][j-1]^a[i][j-2]=a[i-2][j]^a[i][j-2]
A[I][J]=A[I-2][J]^A[I][J-2]=A[I-4][J]^A[I-2][J-2]^A[I-2][J-2]^A[I][J-4]=A[I-4][J]^A[I][J-4]
And so on you can find
A[I][J]=A[I-131072][J]^A[I][J-131072]
Pretreatment a[1..100][1..131172] and a[1..131172][1..100]
For each query answer is A[N][131072+M]^A[131072+N][M]
I think 51nod's topic is really interesting, of course, if it's not so difficult math problems, I would feel more interesting.
At that time has been gradually introduced to the law, but the ability to read the problem is really deficient, and then another point is that the sense of pre-processing will be timed out, did not dare to do so, think it will be wrong (afraid of what Ah, do it again AH)
Code:
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string > #include <cstring> #pragma warning (disable:4996) using namespace Std;int a1[131175];int a2[131175];int r1[105 ][131175];int R2[131175][105];int Main () {int i,m,n,q;a1[1] = 0;a2[1] = 0;memset (r1, 0, sizeof (R1)), memset (R2, 0, sizeof (r 2)); for (i = 2; I <= 131172; i++) {scanf ("%d", &a1[i]); R1[1][i] = A1[i];if (i >= 2 && i <=) r2[1][i ] = A1[i];} for (i = 2; I <= 131172; i++) {scanf ("%d", &a2[i]); r2[i][1] = A2[i];if (i >= 2 && i <=) r1[i][1] = A2[i];} for (M = 2; M <=, m++) {for (n = 2; n <= 131172;n++) {R1[m][n] = R1[m-1][n] ^ r1[m][n-1];}} for (M = 2, M <= 131172; m++) {for (n = 2; n <=, n++) {r2[m][n] = R2[m-1][n] ^ r2[m][n-1];}} scanf ("%d", &q); for (i = 1; I <= Q; i++) {scanf ("%d%d", &n, &m); cout << (r1[n][131072 + m] ^ r2[131072 + n][m]) << Endl;} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
51nod 1346: Recursive