-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathareas.cpp
66 lines (61 loc) · 1.82 KB
/
areas.cpp
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
/*
int sum(int **matrix,int x,int y,int k)
{
int s=0;
for(int i=x;i<(i+k);i++)
{
for(int j=y;j<(y+k);j++)
s+=matrix[x][y];
}
}
*/
int matrixMax(int **matrix,int startx,int starty,int endx,int endy,int k)
{
int max=0;
for(int x=startx;x<=(endx-k+1);x++)
{
for(int y=starty;y<=(endy-k+1);y++)
{
if(matrix[x][y]>max)
max=matrix[x][y];
}
}
//cout<<"max is: "<<startx<<" "<<starty<<" "<<endx<<" "<<endy<<" "<<max<<endl;
return max;
}
void fourCorners(int ***areas,int **matrix,int m,int n,int k,int i,int j)
{
areas[i][j][0]=matrixMax(matrix,0,0,i-1,j-1,k);
areas[i][j][1]=matrixMax(matrix,m-i,0,m-1,j-1,k);
areas[i][j][2]=matrixMax(matrix,m-i,n-j,m-1,n-1,k);
areas[i][j][3]=matrixMax(matrix,0,n-j,i-1,n-1,k);
/*
cout<<"1:"<<i<<" "<<j<<" "<<areas[i][j][0]<<endl;
cout<<"2:"<<i<<" "<<j<<" "<<areas[i][j][1]<<endl;
cout<<"3:"<<i<<" "<<j<<" "<<areas[i][j][2]<<endl;
cout<<"4:"<<i<<" "<<j<<" "<<areas[i][j][3]<<endl;
*/
}
/*
void recur(int ****areas,int **matrix,int m,int n,int k,int startx,int starty,int endx,int endy)
{
if(endx<0 || endy<0 || startx==(m-k) || starty==(n-k))
return;
if(startx==endx && starty==endy)
return;
areas[startx][starty][endx][endy]=max(matrix,startx,starty,endx,endy,k);
recur(areas,matrix,m,n,k,startx+1,starty,endx,endy);
recur(areas,matrix,m,n,k,startx,starty+1,endx,endy);
recur(areas,matrix,m,n,k,startx,starty,endx-1,endy);
recur(areas,matrix,m,n,k,startx,starty,endx,endy-1);
cout<<startx<<" "<<starty<<" "<<endx<<" "<<endy<<endl;
}
*/
void getMaxInArea(int ***areas,int **matrix,int m,int n,int k)
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
fourCorners(areas,matrix,m,n,k,i,j);
}
}