思路:
先将二维的坐标转换成一维的坐标,然后用矩阵存储,然后进行pci路径转移。关键点就是不能从出口处转移。
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 26;
int n,m;
struct Matrix {
int arr[N][N];
Matrix(){};
Matrix operator *( const Matrix &a ) const {
Matrix ret;
for(int i = 1; i <= m * n; i++) {
for(int j = 1; j <= m * n; j++) {
ret.arr[i][j] = 0;
for(int k = 1; k <= m * n; k++) {
if ( i==m*n || k==m*n ) continue;
ret.arr[i][j] |= (arr[i][k] * a.arr[k][j]) ;
}
}
}
return ret;
}
};
Matrix ans;
Matrix item,t;
void pow_M( int x ) {
while ( x ) {
if ( x&1 )
ans = ans * item;
item= item * item;
x /= 2;
}
}
int main()
{
int T;
cin>>T;
int x[4],y[4];
while ( T-- ) {
scanf("%d%d",&n,&m);
memset( item.arr,0,sizeof item.arr );
memset( ans.arr,0,sizeof ans.arr );
for ( int i=1; i<=m*n; i++ )
ans.arr[i][i] =1 ;
for ( int i=1; i<=n; i++ ) {
for ( int j=1; j <=m; j++ ) {
scanf(" ((%d,%d),(%d,%d),(%d,%d),(%d,%d))",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]);
for(int k=0;k<4;k++)
item.arr[ (i-1)*m + j ][ (x[k]-1)*m + y[k] ] = 1;
}
}
memcpy( t.arr , item.arr,sizeof item.arr );
int q;
int time;
cin>>q;
while ( q-- ) {
scanf("%d",&time);
memcpy( item.arr , t.arr , sizeof item.arr );
memset( ans.arr,0,sizeof ans.arr );
for ( int i=1; i<=m*n; i++ )
ans.arr[i][i] =1 ;
pow_M( time );
int cnt = 0;
for ( int i=1; i<=m*n; i++ ) {
if ( ans.arr[1][i] )
++cnt;
}
if ( ans.arr[ 1 ][ n*m ] ) {
if ( cnt==1 ) cout<<"True"<<endl ;
else cout<<"Maybe"<<endl;
} else {
cout<<"False"<<endl;
}
}
cout<<endl;
}
return 0;
}