すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)
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≤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)
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
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
Sample Output 1
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.
Sample Input 2
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
4
26
22
10
2
0
0
0
0
0
Sample Input 3
1000000000 1000000000 0
Sample Output 3
999999996000000004
0
0
0
0
0
0
0
0
0 题意:
给定一个高为h,宽为w的矩阵,然后给你n个黑色块的坐标。
让你求出所有大小为3*3的矩阵分别包含了多少个黑色块,
你只需要输出含有0~9个黑色块的个数的矩阵数量分别是多少。 思路:
由于h和w的数量很大,没有办法进行直接标记模拟。、
我们思考如下:每一个黑色的方块只会对9个3*3的矩阵有贡献。 看图:
看图可以知道,蓝色圆圈的位置如果是黑色块,可以对以红色点为左上角起点的3*3的区间有贡献。
那么我们对每一个黑色块算出的一共9个的贡献矩阵,全部加入到一个数组中,排序后处理答案即可。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
struct node
{
ll x,y;
}a[maxn];
ll n;
ll h,w;
ll xx[]={-,-,-,-,-,-,,,};
ll yy[]={-,-,,-,-,,-,-,};
ll ans[];
ll mod=1e9+;
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
cin>>h>>w>>n;
repd(i,,n)
{
cin>>a[i].x>>a[i].y;
}
vector<ll> v;
repd(i,,n)
{
repd(j,,)
{
ll x=a[i].x+xx[j];
ll y=a[i].y+yy[j];
if(x>=&&x+<=h&&y>=&&y+<=w)
{
// cout<<x<<" "<<y<<endl;
ll num=(x)*mod+y;
v.push_back(num);
}
}
}
sort(ALL(v));
v.push_back(-9ll);
ll ww=1ll;
ll ans0=(h-2ll)*(w-2ll);
for(int i=;i<v.size()-;i++)
{
// db(v[i]);
if(v[i]==v[i+])
{
ww++;
}else
{
ans[ww]++;
ww=1ll;
ans0--;
}
}
cout<<ans0<<endl;
repd(i,,)
{
cout<<ans[i]<<endl;
} return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)的更多相关文章
- ARC063F すぬけ君の塗り絵 2 / Snuke's Coloring 2
题面 一句话题面:给你一些点,求这些点之中夹的最大的矩形周长.(考虑边界) Solution 首先是一个结论,答案矩形一定经过\(x=\frac{w}{2}\)或经过\(y=\frac{h}{2}\) ...
- [arc063]F.すぬけ君の塗り絵2
因为这题考虑可以观察一个性质,答案的下界为 \(2×(max(w,h)+1)\), 因为你至少可以空出一行或一列,因此这个矩形一定会经过 \(x=\frac{w}{2}\) 或 \(y=\frac{h ...
- [Arc063F] Snuke's Coloring 2
[Arc063F] Snuke's Coloring 2 题目大意 给你一个网格图,一些点上有标记,求边长最大空白矩形. 试题分析 专门卡\(\log^2 n\)系列. 首先由题意我们可以找到答案的下 ...
- AtCoder Regular Contest 063 F : Snuke’s Coloring 2 (线段树 + 单调栈)
题意 小 \(\mathrm{C}\) 很喜欢二维染色问题,这天他拿来了一个 \(w × h\) 的二维平面 , 初始时均为白色 . 然后他在上面设置了 \(n\) 个关键点 \((X_i , Y_i ...
- 2018.09.22 atcoder Snuke's Coloring 2(线段树+单调栈)
传送门 就是给出一个矩形,上面有一些点,让你找出一个周长最大的矩形,满足没有一个点在矩形中. 这个题很有意思. 考虑到答案一定会穿过中线. 于是我们可以把点分到中线两边. 先想想暴力如何解决. 显然就 ...
- 2018.09.19 atcoder Snuke's Coloring(思维题)
传送门 谁能想到这道题会写这么久. 本来是一道很sb的题啊. 就是每次选一个点只会影响到周围的九个方格,随便1e9进制就可以hash了,但是我非要作死用stl写. 结果由于技术不够高超,一直调不出来. ...
- 【ARC 063F】Snuke's Coloring 2
Description There is a rectangle in the xy-plane, with its lower left corner at (0,0) and its upper ...
- atcoder C - Snuke and Spells(模拟+思维)
题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...
- Snuke's Coloring 2-1
There is a rectangle in the xy-plane, with its lower left corner at (0,0) and its upper right corner ...
随机推荐
- httpclient+jsoup实现小说线上采集阅读
前言 用过老版本UC看小说的同学都知道,当年版权问题比较松懈,我们可以再UC搜索不同来源的小说,并且阅读,那么它是怎么做的呢?下面让我们自己实现一个小说线上采集阅读.(说明:仅用于技术学习.研究) 看 ...
- 【.NET Core项目实战-统一认证平台】第七章 网关篇-自定义客户端限流
[.NET Core项目实战-统一认证平台]开篇及目录索引 上篇文章我介绍了如何在网关上增加自定义客户端授权功能,从设计到编码实现,一步一步详细讲解,相信大家也掌握了自定义中间件的开发技巧了,本篇我们 ...
- win10连接无线网,开启移动热点,手机连接它手机一直显示获取ip地址中。
*必须要有无线网卡才能设置WIFI首先打开电脑,选中“计算机”或者“我的电脑”,右击进入“管理”选项“.打开“计算机管理”窗口之后,在左栏菜单选项中找到“服务和应用程序”下的“服务”选项,如图点击进入 ...
- [PHP] 抽象类abstract的回顾
1.abstract定义为抽象的类不能被实例化. 2.它里面至少有一个方法是被声明为抽象的,那么这个类就必须被声明为抽象的. 3.被定义为抽象的方法只是声明了其调用方式(参数),不能定义其具体的功能实 ...
- 学JAVA第十天,一维数组及二维数组的使用。
今天老师讲了JAVA数组,之前学C#的时候就学过一维数组,至于二维数组当时只是粗略普及了一下. 现在想学JAVA又学到了数组,但是这次不同,注重讲二维数组,因为老师知道我们都了解一维数组了. 所以现在 ...
- JAVA程序员面试30问(附带答案)
第一,谈谈final, finally, finalize的区别. 最常被问到.final修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承.因此一个类不能 ...
- TensorFlow与Flask结合识别手写体数字
阅读本文约“2.2分钟” TensorFlow框架 ——TensorFlow是谷歌基于DistBelief进行研发的第二代人工智能学习系统 ——可被用于语音识别或图像识别等多项机器学习和深度学习领域 ...
- springboot、springsecurity、jwt权限验证
1.背景 基于前后端分离项目的后端模块: 2.相关技术 springboot全家桶 web模块 security模块:用于权限的验证 mongodb 模块:集成mogodb模块 jwt 用于token ...
- django项目前期准备
本文转载自 https://blog.csdn.net/xiaogeldx/article/details/89037748 Django现状 Django开发前景 Django的厉害之处 在Pyth ...
- MS SQL自定义函数IsPositiveInteger
判断字符串是否为正整数,0开始的的数字不算. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[svf_I ...
