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\n",ans[i]);
    }
    return 0;
}

转载于:https://www.cnblogs.com/keyboarder-zsq/p/5934801.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值