-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1012.cpp
More file actions
65 lines (58 loc) · 1.35 KB
/
1012.cpp
File metadata and controls
65 lines (58 loc) · 1.35 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
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std ;
int T, N, M, K ;
vector< pair <int, int> > arr ;
bool visited[51][51] ;
void input_clear()
{
arr = vector< pair <int, int> >() ;
for(int i = 0 ; i < 51 ; i++)
memset(visited[i], 0, sizeof(bool) * 51) ;
}
void input_setting()
{
int xPoint, yPoint ;
cin >> M >> N >> K;
input_clear() ;
for(int i = 0 ; i < K ; i++)
{
cin >> xPoint >> yPoint ;
arr.push_back(make_pair(xPoint, yPoint)) ;
visited[xPoint][yPoint] = 1 ;
}
}
void find_answer(int x, int y)
{
if(x >= M || y >= N || x < 0 || y < 0) return ;
if(visited[x][y] == 0) return ;
visited[x][y] = 0 ;
int arrX[] = {1, 0, -1, 0} ;
int arrY[] = {0, 1, 0, -1} ;
for(int i = 0 ; i < 4 ; i++)
{
int nextX = arrX[i] + x ;
int nextY = arrY[i] + y ;
find_answer(nextX, nextY) ;
}
return ;
}
int main()
{
SETTING ;
cin >> T ;
for(int i = 0 ; i < T ; i++)
{
int answer = 0 ;
input_setting() ;
for(int i = 0 ; i < arr.size() ; i++)
{
if(visited[arr[i].first][arr[i].second])
{
answer++ ;
find_answer(arr[i].first, arr[i].second) ;
}
}
cout << answer << "\n" ;
}
}