zoj3497 Mistwald (矩阵快速幂+图论)
来源:互联网 发布:linux 查看进程cpu 编辑:程序博客网 时间:2024/05/22 00:53
In chapter 4 of the game Trails in the Sky SC, Estelle Bright and her friends are crossing Mistwald to meet their final enemy, Lucciola.
Mistwald is a mysterious place. It consists of M * N scenes, named Scene (1, 1) to Scene (M, N). Estelle Bright and her friends are initially at Scene (1, 1), the entering scene. They should leave Mistwald from Scene (M, N), the exiting scene. Note that once they reach the exiting scene, they leave Mistwald and cannot come back. A scene in Mistwald has four exits, north, west, south, and east ones. These exits are controlled by Lucciola. They may not lead to adjacent scenes. However, an exit can and must lead to one scene in Mistwald.
Estelle Bright and her friends walk very fast. It only takes them 1 second to cross an exit, leaving a scene and entering a new scene. Other time such as staying and resting can be ignored. It is obvious that the quicker they leave Mistwald, the better.
Now you are competing with your roommate for who uses less time to leave Mistwald. Your roommate says that he only uses P seconds. It is known that he lies from time to time. Thus, you may want to code and find out whether it is a lie.
Input
There are multiple test cases. The first line of input is an integer T ≈ 10 indicating the number of test cases.
Each test case begins with a line of two integers M and N (1 ≤ M, N ≤ 5), separated by a single space, indicating the size of Mistwald. In the next M lines, the ith line contains Npieces of scene information, separated by spaces, describing Scene (i, 1) to Scene (i, N). A scene description has the form "((x1,y1),(x2,y2),(x3,y3),(x4,y4))" (1 ≤ xk ≤ M; 1 ≤ yk ≤ N; 1 ≤ k ≤ 4) indicating the locations of new scenes the four exits lead to. The following line contains an integer Q (1 ≤ Q ≤ 100). In the next Q lines, each line contains an integer P (0 ≤P ≤ 100,000,000), which is the time your roommate tells you.
Test cases are separated by a blank line.
Output
For each P, output one of the following strings in one line: "True" if it cannot be a lie; "Maybe" if it can be a lie; "False" if it must be a lie.
Print a blank line after each case.
Sample Input
23 2((3,1),(3,2),(1,2),(2,1)) ((3,1),(3,1),(3,1),(3,1))((2,1),(2,1),(2,1),(2,2)) ((3,2),(3,2),(3,2),(3,2))((3,1),(3,1),(3,1),(3,1)) ((3,2),(3,2),(3,2),(1,1))312102 1((2,1),(2,1),(2,1),(2,1))((2,1),(2,1),(2,1),(2,1))212
Sample Output
MaybeFalseMaybeTrueFalse
Author: WU, Jun
Contest: The 8th Zhejiang Provincial Collegiate Programming Contest
解析:(先贴着代码,抽空补)
代码:
#include<cstdio>#include<cctype>#include<cstring>using namespace std;int n;int read(){ int ans=0;char tmp; while(!isdigit(tmp=getchar())); do ans=(ans<<3)+(ans<<1)+tmp-'0'; while(isdigit(tmp=getchar())); return ans;}void multi(bool (*x)[25],bool (*y)[25]){ int i,j,k; bool c[25][25]={0}; for(i=0;i<n;i++) for(j=0;j<n;j++) for(k=0;k<n;k++) c[i][j]|=x[i][k]*y[k][j]; for(i=0;i<n;i++) for(j=0;j<n;j++) x[i][j]=c[i][j];}int main(){ //freopen("1.in","r",stdin); int i,j,k,m,t,x,y,q,p; bool st[25][25],a[25][25],b[25][25]; for(scanf("%d",&t);t;t--) { m=read(),n=read(); memset(st,0,sizeof(st)); for(i=0;i<m;i++) for(j=0;j<n;j++) { k=n*i+j; x=read()-1,y=read()-1; if(k!=n*m-1)st[k][n*x+y]=1; x=read()-1,y=read()-1; if(k!=n*m-1)st[k][n*x+y]=1; x=read()-1,y=read()-1; if(k!=n*m-1)st[k][n*x+y]=1; x=read()-1,y=read()-1; if(k!=n*m-1)st[k][n*x+y]=1; } for(n=n*m,q=read();q;q--) { for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=st[i][j],b[i][j]=(i==j); for(p=read();p;multi(a,a),p>>=1) if(p&1)multi(b,a); if(!b[0][n-1]){printf("False\n");continue;} for(i=0;i<n-1;i++)if(b[0][i])break; printf("%s\n",(i<n-1)?"Maybe":"True");} printf("\n");} return 0;}
- zoj3497 Mistwald (矩阵快速幂+图论)
- 快速矩阵幂ZOJ3497
- 链接矩阵快速幂(zoj3497)
- ZOJ 3497 Mistwald【矩阵快速幂】【图论】
- ZOJ 3497 Mistwald(矩阵快速幂)
- ZOJ 3497 Mistwald(矩阵快速幂)
- ZOJ 3497-Mistwald(矩阵快速幂)
- zoj 3497 Mistwald 矩阵快速幂
- zoj 3497 Mistwald 矩阵快速幂
- ZOJ 3497Mistwald(矩阵快速幂)
- zoj 3497 Mistwald 矩阵快速幂
- zoj 3497 Mistwald(矩阵快速幂)
- Mistwald(离散数学关系矩阵+矩阵快速幂+数据读取格式问题)
- ZOJ 3497 Mistwald (矩阵快速幂解决类似图论问题)
- 【已解决】zoj 3497 Mistwald 矩阵快速幂
- zju 3497 Mistwald(矩阵乘法)
- zoj3497
- 【矩阵乘法经典应用】【ZOJ3497】【Mistwa】
- KVM学习笔记
- eclipse导入tomcat run as 没有server
- 今年暑假不AC
- PAT_乙级1031
- 203Remove Linked List Elements
- zoj3497 Mistwald (矩阵快速幂+图论)
- Unity开发中总结的一些小技巧
- 好用的截图方法
- 1.JVM运行时数据区
- c#之new关键字
- hdoj 2544 最短路
- 异或(Exclusive-OR,Wuhan 2009,LA 4487)
- 常用meta整理,页面技术,SEO优化
- zoj1093 dp入门