-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHous_Near_Utility.c
90 lines (83 loc) · 1.69 KB
/
Hous_Near_Utility.c
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
#include <stdio.h>
#include<stdlib.h>
char inp[5][3] = {
{0,1,0},
{1,0,0},
{1,1,0},
{0,0,0},
{0,0,1},
};
int **arr;
int row= sizeof(inp)/sizeof(inp[0]);
int col= sizeof(inp[0])/sizeof(inp[0][0]);
void main(void)
{
/*printf("s= %d\n", sizeof(inp));
printf("row= %d\n", row);
printf("col= %d\n", col);*/
arr = (int **)malloc(row * sizeof(int *));
for(int r=0; r<5; r++)
{
arr[r] = (int*)calloc(0, col * sizeof(int));
}
/*printf("\ninp= \n");
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
printf("%d ", inp[i][j]);
}
printf("\n");
}
printf("\n");*/
int dist=0;
int b=0;
int tr=0;
int result =0;
for(int b=0; b<row; b++)
{
tr=b-1;
if(tr<0)
{
tr=row;
}
for(int j=0; j<col; j++)
{
dist=0;
int i=b;
do
{
if(inp[i][j]==1)
{
arr[b][j] =dist+1;
break;
}
dist++;
i++;
if(i==row)
i=0;
}while(i!=tr+1);
}
}
/*printf("Output-\n");
for(int i=0; i<row; i++)
{
for (int j=0; j<col; j++)
{
printf("%d ", arr[i][j]);
}
printf("\n");
}*/
int act_res= arr[0][0] +arr[0][1]+arr[0][2];
int block =0;
for(int i =0; i<row; i++)
{
result = arr[i][0] +arr[i][1]+arr[i][2];
if(result <act_res)
{
act_res=result;
block =i;
}
}
printf("Block= %d\n", block);
}