51nod-1346: 遞迴

來源:互聯網
上載者:User

標籤:有趣的   [1]   http   class   problem   question   std   min   www   

【傳送門:51nod-1346】簡要題意:

  給出一個式子a[i][j]=a[i-1][j]^a[i][j-1]

  給出a[1][i],a[i][1](2<=i<=131172)

  有n個詢問,每個詢問輸入x,y

  求出a[x+131072][y+131072]

題解:

  真是一道有趣的題目。。

  顯然不能直接做,然後我直接打了個表。。發現a[i][j]=a[i-k][j]^a[i][j-k](k<=min(i,j),且k為偶數)

  那答案不就是a[x+131072][y+131072]=a[x][y+131072]^a[x+131072][y]

  直接暴力得到a[1~100][1~131172]和a[1~131172][1~100]就行了

參考代碼:
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>using namespace std;int a[110][131173];int b[131173][110];int main(){    for(int i=2;i<=131172;i++)    {        scanf("%d",&a[1][i]);        if(i<=100) b[1][i]=a[1][i];    }    for(int i=2;i<=131172;i++)    {        scanf("%d",&b[i][1]);        if(i<=100) a[i][1]=b[i][1];    }    for(int i=2;i<=100;i++)    {        for(int j=2;j<=131172;j++) a[i][j]=a[i-1][j]^a[i][j-1];    }    for(int i=2;i<=131172;i++)    {        for(int j=2;j<=100;j++) b[i][j]=b[i-1][j]^b[i][j-1];    }    int n;    scanf("%d",&n);    while(n--)    {        int x,y;        scanf("%d%d",&x,&y);        printf("%d\n",a[x][y+131072]^b[x+131072][y]);    }    return 0;}
 

51nod-1346: 遞迴

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.