题目:
https://www.acwing.com/problem/content/4513/
注意:
- 运用到
pair
、map
数据结构,多加注意map
的用法 - 暴力遍历数组,二重循环,通过
mp[{dx + i, dy + j}] != rp[{i, j}]
判断
#include<bits/stdc++.h>
using namespace std;
int n, l, s;
typedef pair<int, int> PII;
map<PII, int> mp;
map<PII, int> rp;
vector<PII> qwe;
int main()
{
scanf("%d%d%d", &n, &l, &s);
//利用map读取数据
for (int i = 0; i < n; i++)
{
int first, second;
scanf("%d%d", &first, &second);
mp[{first, second}] = 1;
qwe.push_back({ first,second });
}
for (int i = s; i >= 0; i--)
{
for (int j = 0; j <= s; j++)
{
int x;
scanf("%d", &x);
rp[{i, j}] = x;
}
}
int count = 0;
for (int r = 0; r < qwe.size(); r++)
{
int dx = qwe[r].first, dy = qwe[r].second;
bool flag = true;
for (int i = 0; i <= s; i++)
{
for (int j = 0; j <= s; j++)
{
if (mp[{dx + i, dy + j}] != rp[{i, j}] || dx + i > l || dy + j > l)
{
flag = false;
break;
}
}
if (!flag)
{
break;
}
}
if (flag) count++; //该点满足题意
}
printf("%d\n", count);
return 0;
}