-
Notifications
You must be signed in to change notification settings - Fork 13
/
abcpath.cpp
101 lines (66 loc) · 1.99 KB
/
abcpath.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
using namespace std;
vector<int> count;
struct node
{
int p;
int q;
};
void dfs(char** mat,int h,int w,int t1,int t2,int** x,int** previsit,int** postvisit)
{
x[t1][t2]=true;
previsit[t1][t2]=previsit[t1][t2]+1;
if(((int)mat[t1][t2]-(int)mat[t1+1][t2])==1)
if(x[t1+1][t2]!=true)
dfs(mat,h,w,t1+1,t2,x);
int main()
{
int h,w;
scanf("%d%d",&h,&w);
string s="";
vector<node> v;
char mat[h+2][w+2];
for(int i=0;i<h+2;i++)
{
mat[i][0]='(';
mat[i][w+1]='(';
}
for(int i=0;i<h+2;i++)
{
mat[0][i]='(';
mat[h+1][i]='(';
}
for(int i=1;i<h+1;i++)
for(int j=1;j<w+1;j++)
{
cin>>mat[i][j];
if(mat[i][j]=='A')
{
node temp;
temp.p=i;
temp.q=i;
v.push_back(temp);
}
}
bool x[h+2][w+2];
for(int i=0;i<v.size();i++)
{
s=" ";
int t1=v[i].p;
int t2=v[i].q;
for(int i=0;i<h+2;i++)
for(int j=0;j<w+2;j++)
x[i][j]=0;
for(int i=0;i<h+2;i++)
for(int j=0;j<w+2;j++)
previsit[i][j]=0;
for(int i=0;i<h+2;i++)
for(int j=0;j<w+2;j++)
postvisit[i][j]=0;
dfs(mat,h+2,w+2,t1,t2,x);
system ("pause");
return 0;
}