~~~ Question Link ~~~
Give a graph. Now you need to determine whether it is composed of two basic graphs (which cannot be rotated.
PS: start to use recursion for simulation. It always times out. I 'd better use the teammate method.
Code:
# Include <iostream> # include <algorithm> # define INF 1234567890; using namespace STD; int n = 0, m = 0, X1 = 0, X2 = 0, Y1 = 0, y2 = 0; string m1 [12], m2 [12], m3 [12], M4 [12]; void print (string m1 [12]) {for (INT I = 0; I <n; I ++) cout <M1 [I] <Endl; cout <Endl ;} int cover (string m1 [12], string m2 [12], int X, int y) {for (INT I = x, K = x1; k <= x2; I ++, K ++) {for (Int J = Y, L = Y1; L <= Y2; j ++, l ++) {If (m1 [k] [L] = '. ') Continue; If (m2 [I] [J] =' * '& m1 [k] [l] =' * ') return 0; m2 [I] [J] = m1 [k] [l] ;}// print (m2); return 1 ;}void copy (string m1 [12], string m2 [12]) {for (INT I = 0; I <n; I ++) m2 [I]. assign (m1 [I], 0, n);} void Init () {for (INT I = 0; I <n; I ++) m3 [I]. assign (n ,'. ');} int equal () {for (INT I = 0; I <n; I ++) if (m3 [I]! = M1 [I]) return 0; return 1;} int main () {int I = 0, j = 0, K = 0, L = 0, flag = 0; while (CIN> N> M, N + M! = 0) {for (I = 0; I <n; I ++) CIN> m1 [I]; for (I = 0; I <m; I ++) cin> m2 [I]; X1 = inf; Y1 = inf; x2 = 0; y2 = 0; for (I = 0; I <m; I ++) for (j = 0; j <m; j ++) {If (m2 [I] [J] = '*') {x1 = min (I, X1 ); x2 = max (I, X2); Y1 = min (J, Y1); y2 = max (J, Y2) ;}} flag = 0; for (I = 0; I <n-x2 + x1; I ++) for (j = 0; j <n-y2 + Y1; j ++) {Init (); cover (M2, M3, I, j); copy (M3, M4); For (k = 0; k <n-x2 + x1; k + +) for (L = 0; L <n-y2 + Y1; l ++) {copy (M4, M3); If (m3 [k] [l] = '. '& cover (M2, M3, K, L) {If (equal () {flag = 1; I = N, j = n, k = n, L = n ;}}}if (FLAG) cout <1 <Endl; else cout <0 <Endl;} return 0 ;}