算法练习系列——牛客练习——2024牛客五一集训派对day4

2024牛客五一集训派对day4

A:

链接

题目描述

You have taken the graduation picture of graduates. The picture could be regarded as a matrix A of n×nn \times nn×n, each element in A is 0 or 1, representing a blank background or a student, respectively.

However, teachers are too busy to take photos with students and only took a group photo themselves. The photo could be regarded as a matrix B of 1×m1 \times m1×m where each element is 2 representing a teacher.

As a master of photoshop, your job is to put photo B into photo A with the following constraints:

  • you are not allowed to split, rotate or scale the picture, but only translation.
  • each element in matrix B should overlap with an element in A completely, and each teacher should overlap with a blank background, not shelter from a student.

Please calculate the possible ways that you can put photo B into photo A.

输入描述:

1
2
3
4
5
The first line contains two integers n,m(1≤n,m≤2000) indicating the size of photos A and B. 

In the next $n$ lines,each line contains n characters of '0' or '1',representing the matrix A.

The last line contains m characters of '2', representing matrix B.

输出描述:

1
Output one integer in a line, indicating the answer.

示例1

输入

复制

1
2
3
4
5
6
7
5 3
00000
01110
01110
01110
00000
222

输出

复制

1
6

示例2

输入

复制

1
2
3
4
5
3 2
101
010
101
22

输出

复制

1
0

示例3

输入

复制

1
2
3
4
5
3 1
101
010
101
2

输出

复制

1
4

思路

​ 纯暴力,没啥好说的

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <cstdio>

// #define int long long
#define ull unsigned long long
#define ed '\n'
#define fi first
#define se second
#define fore(i, l, r) for(int i = (int)(l); i <=(int)r; i++)
#define debug(x) cout << "#x = " << x << ed;
#define PI acos(-1)
#define E exp(1)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define me0(st) memset(st, 0, sizeof st)
#define me3f(st) memset(st, 0x3f, sizeof st)
#define pdf(x) printf("%lf", double(x))
#define pif(x) printf("%d ", int(x))
#define scf(x) printf("%d", int(x))
#define re return 0
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;
typedef double db;


const int INF = 1e9;
const int N = 2e3 + 10;
int n, m;
LL ans;
char a[N][N];
void solve() {
int i, j;
char c;
cin >> n >> m;
fore (i, 1, n) {
cin >> a[i];
}

fore (i, 1, n) {
int k = 0;
fore (j, 0, n - 1) {
if (a[i][j] == '1') {
k = 0;
} else {
k++;
}
if (k >= m) {
ans++;
}
}
}

cout << ans;
}
int main()
{
IOS;
int _ = 1;
// cin >> _;

while(_--) {
solve();
}

re;
}

……….