• 6468: Snuke's Coloring


    6468: Snuke's Coloring

    时间限制: 2 Sec  内存限制: 128 MB
    提交: 50  解决: 22
    [提交][状态][讨论版][命题人:admin]

    题目描述

    We have a grid with H rows and W columns. At first, all cells were painted white.
    Snuke painted N of these cells. The i-th ( 1≤i≤N ) cell he painted is the cell at the ai-th row and bi-th column.
    Compute the following:
    For each integer j ( 0≤j≤9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

    Constraints
    3≤H≤109
    3≤W≤109
    0≤N≤min(105,H×W)
    1≤ai≤H (1≤i≤N)
    1≤bi≤W (1≤i≤N)
    (ai,bi)≠(aj,bj) (i≠j)

    输入

    The input is given from Standard Input in the following format:
    H W N
    a1 b1
    :
    aN bN

    输出

    Print 10 lines. The (j+1)-th ( 0≤j≤9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

    样例输入

    4 5 8
    1 1
    1 4
    1 5
    2 3
    3 1
    3 2
    3 4
    4 4
    

    样例输出

    0
    0
    0
    2
    4
    0
    0
    0
    0
    0
    

    提示


    There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

    来源

    ABC045&ARC061 


    题意:一个h*w的棋盘,涂黑n个格子,求含有0~9个黑格子的3*3的矩阵分别有多少个

    思路:

    h和w的数据范围是1e9  显然不能开二维矩阵存涂黑的格子。

    每个黑格子只对周围九个3*3的矩阵有贡献,那么可以存一下左上角格子的坐标,然后统计一下就可以了。


    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=1e6+10,inf=1e9+7;
    typedef long long ll;
    ll h,w,node[maxn],n,a,b,cnt=0,zero,ans[15];
    
    int main(){
        scanf("%lld%lld%lld",&h,&w,&n);
        zero=(h-2)*(w-2);
        while(n--){
            scanf("%lld%lld",&a,&b);
            for (int i=-2;i<=0;i++){
                for (int j=-2;j<=0;j++){
                    if(a+i>=1 && a+i <=h-2 && b+j>=1 &&b+j <=w-2){
                        node[cnt++]=inf*(a+i)+(b+j);
                    }
                }
            }
        }
        sort(node,node+cnt);
        for (int i=0,tmp=1;i<cnt;i++){
            if(node[i]==node[i+1]) tmp++;
            else ans[tmp]++,zero--,tmp=1;
        }
        printf("%lld
    ",zero);
        for (int i=1;i<10;i++)
            printf("%lld
    ",ans[i]);
        return 0;
    }
    

  • 相关阅读:
    1025WHERE执行顺序以及MySQL查询优化器
    1025基础REDIS
    1025关于explain的补充1
    1021mysql 全外连接
    python开发进程:进程开启方式&多进程
    python开发面向对象进阶:反射&内置函数
    python开发socket套接字:粘包问题&udp套接字&socketserver
    python开发面向对象基础:封装
    python开发模块基础:异常处理&hashlib&logging&configparser
    python开发面向对象基础:接口类&抽象类&多态&钻石继承
  • 原文地址:https://www.cnblogs.com/acerkoo/p/9490322.html
Copyright © 2020-2023  润新知