"Portal: 51nod-1346" Brief test Instructions:
Give a formula A[i][j]=a[i-1][j]^a[i][j-1]
Give A[1][i],a[i][1] (2<=i<=131172)
There are n queries, each asking input x, y
Find out a[x+131072][y+131072]
The following:
It's really an interesting topic.
Obviously can't do it directly, and then I hit a table directly. Found A[i][j]=a[i-k][j]^a[i][j-k] (k<=min (I,j), and K is even)
The answer is A[x+131072][y+131072]=a[x][y+131072]^a[x+131072][y]
Direct violence get a[1~100][1~131172] and a[1~131172][1~100] on the line
Reference Code:
#include <cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>using namespacestd;inta[ the][131173];intb[131173][ the];intMain () { for(intI=2; i<=131172; i++) {scanf ("%d", &a[1][i]); if(i<= -) b[1][i]=a[1][i]; } for(intI=2; i<=131172; i++) {scanf ("%d", &b[i][1]); if(i<= -) a[i][1]=b[i][1]; } for(intI=2; i<= -; i++) { for(intj=2; j<=131172; j + +) a[i][j]=a[i-1][j]^a[i][j-1]; } for(intI=2; i<=131172; i++) { for(intj=2; j<= -; j + +) b[i][j]=b[i-1][j]^b[i][j-1]; } intN; scanf ("%d",&N); while(n--) { intx, y; scanf ("%d%d",&x,&y); printf ("%d\n", a[x][y+131072]^b[x+131072][y]); } return 0;}
51nod-1346: Recursion