50005. Pattern Recognition

難度:2/5 Used Time: 9:58

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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int n, k, m, d;
int arr[12][12];
int target[12][12];
int ans_x = -1, ans_y = -1;

inline static int this_abs(int n){
if(n < 0) return -n;
else return n;
}

inline static void ipt(){
scanf("%d %d %d %d", &n, &k, &m, &d);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d", &arr[i][j]);
for(int i = 0; i < k; i++) for(int j = 0; j < k; j++) scanf("%d", &target[i][j]);
}

inline static int count_target(){
int cnt = 0;
for(int i = 0; i < k; i++) for(int j = 0; j < k; j++){
cnt += target[i][j];
}
return cnt;
}
inline static int count_arr(int x, int y){
int cnt = 0;
for(int i = 0; i < k; i++) for(int j = 0; j < k; j++){
cnt += arr[x + i][y + j];
}
return cnt;
}
inline static int count_mismatch(int x, int y){
int cnt = 0;
for(int i = 0; i < k; i++) for(int j = 0; j < k; j++){
if(arr[x + i][y + j] != target[i][j]) cnt++;
}
return cnt;
}

int main(){
ipt();

int target_sum = count_target();
for(int i = 0; i < n - k + 1; i++){
for(int j = 0; j < n - k + 1; j++){
int mismatch = count_mismatch(i, j);
int diff = this_abs(count_arr(i, j) - target_sum);

if(mismatch <= m && diff <= d){
ans_x = i;
ans_y = j;
}
}
}

printf("%d %d\n", ans_x, ans_y);
}


50005. Pattern Recognition
https://aaronlin1229.github.io/judgegirl_50005/
Author
Akizumi
Posted on
July 17, 2023
Licensed under