2241: [SDOI2011]打地鼠 暴力

无脑暴力= =

#include<bits/stdc++.h>
using namespace std;
int n,m,sum,ans,a[105][105],b[105][105];
inline int read()
{
    int a=0,f=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
    while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
    return a*f;
}
inline bool judge(int x,int y)
{
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)   
            b[i][j]=a[i][j];
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            if (b[i][j])
            {
                if (i+x-1<=n&&j+y-1<=m)
                {
                    int t=b[i][j];
                    for (int k=i;k<i+x;k++)
                        for (int l=j;l<j+y;l++)
                        {
                            b[k][l]-=t;
                            if (b[k][l]<0) return 0;
                        }
                }
                else return 0;
            }
    return 1;
}                   
int main()
{
    n=read(); m=read();
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            a[i][j]=read(),sum+=a[i][j];
    ans=sum;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            if (sum%(i*j)==0&&sum/(i*j)<ans) 
                if (judge(i,j)) ans=sum/(i*j);
    cout << ans;
    return 0;
}

你可能感兴趣的:(2241: [SDOI2011]打地鼠 暴力)