51nod-1346: Recursion

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.