zoukankan      html  css  js  c++  java
  • BZOJ4972 小Q的方格纸

      每个格子记录其左下的45°直角梯形区域的和及左下矩形区域的和即可。

    #include<iostream> 
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define N 3010
    #define M 3000010
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
        int x=0,f=1;char c=getchar();
        while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
        while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        return x*f;
    }
    int n,m,q;
    unsigned int A,B,C,ans,p[M],a[N][N],b[N][N];
    inline unsigned int rng61()
    {
        A^=A<<16;
        A^=A>>5;
        A^=A<<1;
        unsigned int t=A;
        A=B;
        B=C;
        C^=t^A;
        return C;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("bzoj4972.in","r",stdin);
        freopen("bzoj4972.out","w",stdout);
        const char LL[]="%I64d
    ";
    #else
        const char LL[]="%lld
    ";
    #endif
        scanf("%d%d%d%u%u%u",&n,&m,&q,&A,&B,&C);
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
            a[i][j]=rng61();
        for (int i=n;i>=1;i--)
            for (int j=1;j<=m;j++)
            b[i][j]=a[i][j]+=a[i+1][j];
        for (int i=n;i>=1;i--)
            for (int j=1;j<=m;j++)
            a[i][j]+=a[i+1][j-1],b[i][j]+=b[i][j-1];
        p[0]=1;for (int i=1;i<=q;i++) p[i]=p[i-1]*233;
        for (int i=1;i<=q;i++)
        {
            int x=rng61()%n+1,y=rng61()%m+1,k=rng61()%min(x,y)+1;
            unsigned int tot=a[x-k+1][y]-a[x+1][y-k]-b[x+1][y]+b[x+1][y-k];
            ans+=tot*p[q-i];
        }
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    YTU 2802: 判断字符串是否为回文
    YTU 2392: 求各位数字之和
    YTU 2391: 求素数
    HDU 2064:汉诺塔III
    HDU 2187:悼念512汶川大地震遇难同胞——老人是真饿了
    HDU 2036:改革春风吹满地
    HDU 1081:To The Max
    HDU 1257:最少拦截系统
    YTU 2425: C语言习题 输出月份
    YTU 2420: C语言习题 不等长字符串排序
  • 原文地址:https://www.cnblogs.com/Gloid/p/10053949.html
Copyright © 2011-2022 走看看