-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathBoard.cpp
69 lines (58 loc) · 1.84 KB
/
Board.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
/*
Name: Gourav Singh
https://www.linkedin.com/in/gouravsingh2580/
*/
/*
Gary has a board of size NxM. Each cell in the board is a coloured dot. There exist only 26 colours denoted by uppercase Latin characters (i.e. A,B,...,Z). Now Gary is getting bore and wants to play a game. The key of this game is to find a cycle that contain dots of same colour. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:
1. These k dots are different: if i ≠ j then di is different from dj.
2. k is at least 4.
3. All dots belong to the same colour.
4. For all 1 ≤ i ≤ k - 1: di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.
Since Gary is colour blind, he wants your help. Your task is to determine if there exists a cycle on the board.
Assume input to be 0-indexed based.
Input Format :
Line 1 : Two integers N and M, the number of rows and columns of the board
Next N lines : a string consisting of M characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.
Output Format :
Return 1 if there is a cycle else return 0
Constraints :
2 ≤ N, M ≤ 50
Sample Input :
3 4
AAAA
ABCA
AAAA
Sample Output :
1
*/
#include <bits/stdc++.h>
#define MAXN 51
using namespace std;
int helper(char board[][MAXN], int n, int m, int* visited){
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if ()
{
}
}
}
}
int solve(char board[][MAXN],int n, int m)
{
int* visited = new int[n]();
return helper(board, n, m, visited);
}
int main( int argc , char ** argv )
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL) ;
int N,M,i;
char board[MAXN][MAXN];
cin>>N>>M;
for(i = 0;i < N; i++){
cin>>board[i];
}
cout<<solve(board,N,M)<<endl;
}