集训队专题(2)1006 Mistwald
来源:互联网 发布:linux服务器访问外网 编辑:程序博客网 时间:2024/06/05 09:29
Mistwald
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 54 Accepted Submission(s) : 23
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 N pieces 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
此题用到的是矩阵的一个很基础的用法:位置变换。这中间还可以用到位运算的小技巧做判断^^。
#include <cstdio>#include <cstring>struct Matrix{int mat[30][30];}unit,init;int N,M,T;void Init() { scanf("%d%d",&N,&M); getchar(); int i,j,x1,y1,x2,y2,x3,y3,x4,y4; memset(init.mat,0,sizeof(init.mat));//每次清零! for(i=1; i<=N; i++) for(j=1; j<=M; j++) { scanf("((%d,%d),(%d,%d),(%d,%d),(%d,%d))",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); getchar(); if ((i-1)*M+j == N*M) continue;//舍掉终点的出边 init.mat[(i-1)*M+j][(x1-1)*M+y1]=1; init.mat[(i-1)*M+j][(x2-1)*M+y2]=1; init.mat[(i-1)*M+j][(x3-1)*M+y3]=1; init.mat[(i-1)*M+j][(x4-1)*M+y4]=1; unit.mat[(i-1)*M+j][(i-1)*M+j]=1; } } Matrix multi(Matrix a,Matrix b) { int i,j,k; Matrix c; for(i=1;i<=T;i++) for(j=1;j<=T;j++) { c.mat[i][j]=0; for(k=1;k<=T;k++) c.mat[i][j] |= (a.mat[i][k]&b.mat[k][j]); } return c; } Matrix cal(int k)//矩阵二分快速幂 { Matrix i=init,ans=unit; while(k){ if(k&1) ans = multi(ans,i); i = multi(i,i); k >>= 1; } return ans; } int main() { int t; scanf("%d",&t); while(t--) { Init(); T = N*M; int num,q; scanf("%d",&num); int i; while(num--) { scanf("%d",&q); Matrix r=cal(q); if(r.mat[1][T]==0) printf("False\n"); else { for(i=1;i<=T;i++) { if(r.mat[1][i]) break; } if(i == T) printf("True\n"); else printf("Maybe\n"); } } printf("\n"); } return 0; }
- 集训队专题(2)1006 Mistwald
- 集训队专题(1)1006 单词数
- 集训队专题(5.1)1006 Channel Allocation
- 集训队专题(7)1006 Going Home
- 集训队专题(9)1006 MooFest
- 集训队专题(2)1001 Fibonacci
- 集训队专题(2)1002 Tr A
- 集训队专题(2)1004 Queuing
- 集训队专题(2)1007 Evolution
- 集训队专题(3)1006 一个人的旅行
- 集训队专题(6)1006 Girls and Boys
- 集训队专题(8)1006 Yet Another Multiple Problem
- 集训队专题(2)1003 Matrix Power Series
- 集训队专题(2)1005 A Simple Math Problem
- 集训队专题(1)1001 Immediate Decodability
- 集训队专题(1)1002 统计难题
- 集训队专题(1)1003 Phone List
- 集训队专题(1)1005 Ancient Printer
- deep learning tutorials 的翻译版+theano教程的翻译版本
- JSONException: Value of type java.lang.String cannot be converted to JSONObject
- 关于linux的用户,组,以及权限的知识结构
- leetcode 3 Longest Substring Without Repeating Characters
- ZOJ2856 - Happy Life
- 集训队专题(2)1006 Mistwald
- 20160130交易记录
- 【Android】【笔记】《Android 入门经典》part 12 线程与消息处理
- 一个不用密码的用户系统
- git-使用指南
- LeetCode #237 Delete Node in a Linked List
- 遍历新姿势
- opencv(2)
- hdoj 5616 Jam's balance 【母函数】