AtCoder Regular Contest 061 DSnuke's Coloring

http://arc061.contest.atcoder.jp/tasks/arc061_b
题意:
H行W列的矩阵中,然后挖了n个洞,输出j(0-9)行,对于第i行输出,有多少个3*3区域中有i个洞;

思路:
对于一个黑色的格子,只有9个3*3的矩阵才能包含他。
所以只有处理m个黑格子就行了。
对于每个黑格子,我默认把3*3的左上角代表这个矩阵。
这样还不够,因为没有那么大的矩阵表示方法,所以换一个表示就是把矩阵中每个格子标记;
处理一下,最后输出就好了;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL h,w,n;
map<LL,LL>mp;
LL ans[10];
LL dx[9]={-2,-2,-2,-1,-1,-1,0,0,0};
LL dy[9]={-2,-1,0,-2,-1,0,-2,-1,0};

void Add(LL x,LL y)
{
    LL a,b;
    LL temp;
    for(int i=0;i<9;i++)
    {
        a=x+dx[i];
        b=y+dy[i];
        if(a<1||b<1||a>h-2||b>w-2)
            continue;
        temp=(h-2)*(b-1)+a;
        mp[temp]++;
    }
}

int main()
{
    LL x,y;
    scanf("%lld%lld%lld",&h,&w,&n);
    for(LL i=0;i<n;i++)
    {
        scanf("%lld%lld",&x,&y);
        Add(x,y);
    }
    memset(ans,0,sizeof(ans));
    ans[0]=(h-3)*(w-2)+w-2;
    LL temp;
    map<LL,LL>::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        temp=it->second;
        ans[temp]++;
        ans[0]--;
    }
    for(LL i=0;i<=9;i++)
    {
        printf("%lld
",ans[i]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934801.html