D - すぬけ君の塗り絵 / Snuke's Coloring(思维+离散)

12 篇文章 0 订阅
2 篇文章 0 订阅

题目链接:https://atcoder.jp/contests/arc061/tasks/arc061_b

Problem Statement

We have a grid with HH rows and WW columns. At first, all cells were painted white.

Snuke painted NN of these cells. The ii-th ( 1≤i≤N1≤i≤N ) cell he painted is the cell at the aiai-th row and bibi-th column.

Compute the following:

  • For each integer jj ( 0≤j≤90≤j≤9 ), how many subrectangles of size 3×33×3 of the grid contains exactly jj black cells, after Snuke painted NN cells?

Constraints

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

Input

The input is given from Standard Input in the following format:

HH WW NN
a1a1 b1b1
:
aNaN bNbN

Output

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


Sample Input 1 Copy

Copy

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

Sample Output 1 Copy

Copy

0
0
0
2
4
0
0
0
0
0

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


Sample Input 2 Copy

Copy

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2 Copy

Copy

4
26
22
10
2
0
0
0
0
0

Sample Input 3 Copy

Copy

1000000000 1000000000 0

Sample Output 3 Copy

Copy

999999996000000004
0
0
0
0
0
0
0
0
0

题意:

给你一和h行w列的网格(开时时每个网格都是白色的)

然后给出n个点然后把这些点变成黑色。让你分别求出有0,1,2,...9个的黑色的子3*3网格的数量。

思路:


如上图所示:每一个给定的黑色的点都可以关联有9个点(每个点代表一个以改点为左上方顶点的3*3网格)。

然后让每个矩阵的都+1.

#include<bits/stdc++.h>
#define ll long long
const int maxn = int(1e5) + 7;
using namespace std;
ll inf=1e9+7;
ll a[900009];
ll sum[20];
int main()
{
    ll h,w,n;
    scanf("%lld%lld%lld",&h,&w,&n);
    ll x,y;
    int k=0;
    ll zo=(h-2)*(w-2);//一共有多少个3*3子网格。(初始含有0个黑色的数量)。
    for(ll i=1;i<=n;i++)
    {
        //cin>>x>>y;
        scanf("%lld%lld",&x,&y);
        for(ll i=0;i<=2;i++)
        for(ll j=0;j<=2;j++)
        {
            if(x-i>=1&&x-i<=h-2&&y-j>=1&&y-j<=w-2)
            {

                a[k++]=inf*(x-i)+(y-j);//这里是为了保证每个代表3*3的子网格的数都不一样。
            }
        }
    }
    sort(a,a+k);
    ll t=1;
    for(int i=0;i<k;i++)
    {
        if(a[i]==a[i+1])t++;//相同的a[i]代表同一个3*3网格。相同的加一块就代表这个3*3网格含
有几个黑色方块。
        else
        {
            sum[t]++;t=1;zo--;
        }
    }
    cout<<zo<<endl;//0个黑色的数量3*3网格数量。
    for(int i=1;i<=9;i++)
    {
        cout<<sum[i]<<endl;
    }
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值