-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathLost Representative.cpp
82 lines (77 loc) · 1.6 KB
/
Lost Representative.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<bits/stdc++.h>
using namespace std;
int arr[1000][1000];
int visited[1000][1000];
int calculator(int x, int y, int current, int n)
{
int i=x, j=y;
if(i>=n || j>=n)
{
return 0;
}
if(i<0 || j<0)
{
return 0;
}
else if(visited[i][j]==1)
{
return 0;
}
else if(arr[i][j]==0)
{
visited[i][j]=1;
return 0;
}
else if(arr[i][j]==1 && visited[i][j]==0)
{
visited[i][j]=1;
current = calculator(i+1,j,current,n) + calculator(i,j+1,current,n) + calculator(i-1,j,current,n) + calculator(i,j-1,current,n) + 1;
}
return current;
}
int main()
{
int n;
cin>>n;
while(n--)
{
int t,i,j;
cin>>t;
for(i=0;i<t;i++)
{
for(j=0;j<t;j++)
{
cin>>arr[i][j];
visited[i][j]=0;
}
}
int k,count=0,tp,a1,a2;
cin>>k;
for(i=0;i<t;i++)
{
for(j=0;j<t;j++)
{
if(arr[i][j]==1 && visited[i][j]==0)
{
tp=calculator(i,j,1,t);
}
if(tp==k)
{
count=1; a1=i; a2=j;
break;
}
}
if(tp==k)
{
count=1;
break;
}
}
if(count==0)
cout<<"-1 -1";
else
cout<<a1<<" "<<a2;
cout<<endl;
}
return 0;
}