AtCoder Regular Contest 061 D - すぬけ君の塗り絵 / Snuke's Coloring

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

题目:

D - すぬけ君の塗り絵 / Snuke's Coloring


Time limit : 3sec / Memory limit : 256MB

Score : 400 points

Problem Statement

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≤iN ) 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≤Nmin(105,H×W)
  • 1≤aiH (1≤iN)
  • 1≤biW (1≤iN)
  • (ai,bi)≠(aj,bj) (ij)

Input

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

H W N
a1 b1
:
aN bN

Output

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.

Sample Input 1

Copy

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

Sample Output 1

Copy

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.

题意:给你 H * W 个格子 然后告诉你N个格子是黑色,然后问你可以构成的3*3的格子中(包括黑色块数从0-9) 对于构成的3*3格子它的值等于3*3格子中黑色块的个数,最后问你对于0-9这10个值都分别有多少个3*3的格子

 思想:对于一个黑色的格子来说,假如(x,y)是黑色  他能影响到以(x-2,y-2)  (x-1,y-2)  (x,y-2)  (x-2,y-1)  (x-1,y-1)  (x,y-1)  (x-2,y)  (x,y-1),(x,y)这样九个点为左顶点的格子,因为输入的时候统计下就行了,sort去重,0的话用总共的3*3矩形个数-(1-9)的个数就行了

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
const long long mod = 1e9+7;
long long Sort[maxn];
long long ans[maxn];
int dir[9][2]={-2,-2,-2,-1,-2,0,-1,-2,-1,-1,-1,0,0,-2,0,-1,0,0};
int tot;
int main()
{
	long long H,W,N;
	scanf("%lld%lld%lld",&H,&W,&N);
	long long Ans=(long long)(H-2)*(long long)(W-2);
	for(int i=0;i<N;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		for(int j=0;j<9;j++)
		{
			int xx=x+dir[j][0];
			int yy=y+dir[j][1];
			if(xx>=1 && xx<=H-2 &&yy>=1 && yy<=W-2)
			{
				Sort[tot++] = xx * mod + yy;
			}
		}
	}
	sort(Sort,Sort+tot);
	int cnt=1;
	for(int i=0;i<tot;i++)
	{
		if(Sort[i]==Sort[i+1])
			cnt++;
		else
		{
			ans[cnt]++;
			cnt=1;
			Ans--;
		}
	}
	printf("%lld",Ans);
	for(int i=1;i<10;i++)
		printf(" %lld",ans[i]);
	printf("\n");
	
	
	return 0;
}

  

猜你喜欢

转载自blog.csdn.net/passer__/article/details/81184142
今日推荐