-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimageoverlap.cpp
More file actions
40 lines (32 loc) · 893 Bytes
/
imageoverlap.cpp
File metadata and controls
40 lines (32 loc) · 893 Bytes
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
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int largestOverlap(vector<vector<int> >&, vector<vector<int> >&);
int main()
{
vector<vector<int> > A{ {1,1,0}, {0,1,0}, {0,1,0} };
vector<vector<int> > B{ {0,0,0}, {0,1,1}, {0,0,1} };
int res = largestOverlap(A, B);
cout<<res;
}
int largestOverlap(vector<vector<int> >& A, vector<vector<int> >& B)
{
vector<int> a, b;
int n=A.size();
int res=0;
map<int, int> co;
for(int i=0; i<n*n; i++)
{
if(A[i/n][i%n] == 1)
a.push_back((i/n)*100+(i%n));
if(B[i/n][i%n] == 1)
b.push_back((i/n)*100+(i%n));
}
for(auto i:a)
for(auto j:b)
co[i-j]++;
for(auto v:co)
res=max(res, v.second);
return res;
}