• 【JZOJ6360】最大菱形和(rhombus)


    description


    analysis

    • 容易想到把原矩阵翻转(45°),然后每个数再用(0)隔开

    • 然后就变成了求最大子正方形,求完二维前缀和之后就很好做了


    code

    #pragma GCC optimize("O3")
    #pragma G++ optimize("O3")
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define MAXN 6005
    #define ha 19260817
    #define ll long long
    #define reg register ll
    #define fo(i,a,b) for (reg i=a;i<=b;++i)
    #define fd(i,a,b) for (reg i=a;i>=b;--i)
    
    using namespace std;
    
    ll a[3005][3005],b[MAXN][MAXN];
    ll n,m,h,type,ans=-ha;
    ll Seed,A,B,C,MOD;
    
    inline ll read()
    {
    	ll x=0,f=1;char ch=getchar();
    	while (ch<'0' || '9'<ch){if (ch='-')f=-1;ch=getchar();}
    	while ('0'<=ch && ch<='9')x=x*10+ch-'0',ch=getchar();
    	return x*f;
    }
    inline ll max(ll x,ll y){return x>y?x:y;}
    inline ll Random(){C++,Seed=(Seed*A+B*C)%MOD;return Seed;}
    inline ll Random_int(){ll tmp=Random();if (Random()&1)tmp*=-1;return tmp;}
    inline ll calc(ll x,ll y,ll xx,ll yy){return b[xx][yy]-b[x-1][yy]-b[xx][y-1]+b[x-1][y-1];}
    int main()
    {
    	//freopen("T1.in","r",stdin);
    	freopen("rhombus.in","r",stdin);
    	freopen("rhombus.out","w",stdout);
    	n=read(),m=read(),h=read(),type=read();
    	if (type)
    	{
    		Seed=read(),A=read(),B=read(),C=read(),MOD=read();
    		fo(i,1,n)fo(j,1,m)a[i][j]=Random_int();
    	}
    	else {fo(i,1,n)fo(j,1,m)a[i][j]=read();}
    	fo(i,1,n)fo(j,1,m)b[i-j+m][i+j]=a[i][j];
    	fo(i,1,n+m)fo(j,1,n+m)b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
    	fo(i,1,n+m)for (reg j=((m-i)&1)?1:0;j<=n+m;j+=2)
    	{
    		ll tmpx=(i+j-m)/2,tmpy=j-tmpx;
    		if (h<=tmpx && tmpx<=n-h+1 && h<=tmpy && tmpy<=m-h+1)ans=max(ans,calc(i-h+1,j-h+1,i+h-1,j+h-1));
    	}
    	printf("%lld
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    扑克牌顺子
    数组转 二叉树 ,并且输出二叉树的右视图
    数组中逆序对(归并排序思想)
    链表数字加和
    回文数字
    数组中 只出现一次的数
    判断是否有从根节点到叶子节点的节点值之和等于 sum
    双指针求 3个数和 为0的 数
    vue项目将css,js全部打包到html文件配置
    webpack4配置优化
  • 原文地址:https://www.cnblogs.com/horizonwd/p/11551133.html
Copyright © 2020-2023  润新知