-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (84 loc) · 2.41 KB
/
main.cpp
File metadata and controls
92 lines (84 loc) · 2.41 KB
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
83
84
85
86
87
88
89
90
91
92
#include<fstream>
#include<iostream>
using namespace std;
#include"areas.cpp"
#include"input.cpp"
#include"tfunc.cpp"
#include"parallel.cpp"
int maxm(int x,int y)
{
if(x>y)
return x;
return y;
}
int getMaxSum(int ***areas,int **matrix,int M,int N,int K)
{
int sum=0;
for(int i=0;i<=M-K;i++)
{
for(int j=0;j<=N-K;j++)
{
for(int x=0;x<=M-K;x++)
{
for(int y=0;y<=N-K;y++)
{
int max=0;
if(intersect(i,j,i+K-1,j+K-1,x,y,K)==0)
{
//get the 3rd matrix as the maximum in all remaining areas
max=maxm(max,Tfun(areas,j,i,y,x,y-1,x-1,N,M,K));
max=maxm(max,Tfun(areas,j,i,y,x,y-1,x+K,N,M,K));
max=maxm(max,Tfun(areas,j,i,y,x,y+K,x-1,N,M,K));
max=maxm(max,Tfun(areas,j,i,y,x,y+K,x+K,N,M,K));
max=maxm(max,bottom(areas,N,M,y+K,i,j,K));
max=maxm(max,right(areas,N,M,x+K,i,j,K));
int tmp=(matrix[i][j]+matrix[x][y]+max);
if(tmp>sum)
{
sum=tmp;
}
}
}
}
}
}
return sum;
}
int main(int argc, char *argv[])
{
//read test file
int M,N; //M is no. of columns and N is no. of rows
ifstream input;
if(argc != 3)//To make sure that K is inputed.
{
cout<<"Input format is: './main <testFile> <K>'\n";
return 0;
}
input.open(argv[1], ios::in);
input>>M;
input>>N;
input.close();
int K= atoi(argv[2]);//
//int K=2;
if(K<=0)
{
cout<<"incorrect value of K..."<<endl;
return 0;
}
if(!(((K<=M && M<(2*K)) && N>=(3*K)) || (((2*K)<=M && M<(3*K)) && N>=(2*K)) || (((3*K)<=M) && N>=K)))//Make sure that K is less than M and N
{
cout<<"K is too large..."<<endl;
return 0;
}
int **inputArray = inputFunction(argv[1]);
int **sumArray= getSumArray(inputArray, M, N, K);
int ***areas=new int**[M+1];
for(int i=0;i<=M;i++)
{
areas[i]=new int*[N+1];
for(int j=0;j<=N;j++)
areas[i][j]=new int[4];
}
getMaxInArea(areas,sumArray,M,N,K);
cout<<"Maximum output is:"<<getMaxSum(areas,sumArray,M,N,K)<<endl;
}