一开始看不出来是快速幂矩阵的题目

先要把整个地图离散化为1,2,3,4,。。。。

连成一个有向图

邻接矩阵的平方意为:假如a->b  且b->c     那么一次平方后   a->c    相当于floyd路径的连通

所以p次方就是   该矩阵经过p次幂     如果路径为1 则代表可以走

离散化   i*m+j  ; x*m+y        i,j,x,y必须是基于0~n-1 标准的!

#include <iostream>
#include <cstdio>
#include<cstring> using namespace std; typedef long long ll; struct Matrix{
ll m[][];
}; int n,m;
int siz; Matrix Mul(Matrix a, Matrix b)
{
Matrix c;
memset(c.m, , sizeof(c.m));
for (int i = ; i < siz; i++)
{
for (int j = ; j < siz; j++)
{
for (int k = ; k < siz; k++)
{
c.m[i][j] = (c.m[i][j] + (a.m[i][k] * b.m[k][j]) ) ;
}
}
}
return c;
} Matrix fastm(Matrix a, ll num)
{
Matrix res;
memset(res.m, , sizeof(res.m));
for(int i=;i<siz;i++)
res.m[i][i]=;
while (num)
{
if (num & )
res = Mul(res, a);
num >>= ;
a = Mul(a, a);
}
return res;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
getchar();
Matrix a;
memset(a.m,,sizeof(a.m));
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
int x1,y1,x2,y2,x3,y3,x4,y4;
scanf("((%d,%d),(%d,%d),(%d,%d),(%d,%d))",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
getchar();
if(i==n-&&j==m-) continue;//到达结尾就结束 所以不处理
int now=i*m+j;
a.m[now][(x1-)*m+y1-]=;
a.m[now][(x2-)*m+y2-]=;
a.m[now][(x3-)*m+y3-]=;
a.m[now][(x4-)*m+y4-]=;
}
}
siz=n*m;
int Q;
scanf("%d",&Q);
while(Q--)
{
int p;
scanf("%d",&p);
Matrix res=fastm(a,p);
int flag=;
if(res.m[][siz-]==)
printf("False\n");
else
{
for(int i=;i<siz-;i++)
{
if(res.m[][i]){
flag=;
break;
}
}
if(flag==) printf("Maybe\n");
else printf("True\n");
}
}
printf("\n");
}
return ;
}

Mistwald POJ的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. 表格重新加载 where 携带上次值问题

    表格重载两种方式: 方式一: tableIns.reload(options)   注意这种方式的重载是不会携带上次数据加载时的where值     //使用 第一次渲染返回的对象 var table ...

  2. JSON和JSONP的区别,以及使用方法

    (一)场景 在拉京东城市选择的基础数据时候,遇到被服务器拒绝的情况,也就是ajax跨域问题 (二)json和jsonp 说的直白一点,在我们做ajax异步的一些功能的时候,一定会或多或少的遇到两个问题 ...

  3. centOS6.4 extundelete工具恢复rm -rf 删除的目录[转]

    原文:http://www.cnblogs.com/patf/p/3368765.html PS:补充下,我在fedora 19上运行的时候遇到的一个问题: 1 [root@localhost ext ...

  4. maven阿里云镜像

    <mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorO ...

  5. Epoll模型

    Epoll模型 相比于select,epoll最大的好处在于它不会随着监听fd数目的增长而降低效率.因为在内核中的select实现中,它是采用轮询来处理的,轮询的fd数目越多,自然耗时越多.并且,在l ...

  6. Python3学习笔记11-循环语句

    条件判断使用if,需要加上冒号,当条件判断为True时,执行if下的代码块,为false就什么也不做 只要var1不是0,非空字符串,非空list等,就判断为True.否则为False var1 = ...

  7. windows2008r2系统破解登录密码方法

    破解windows 2008 r2系统登录密码方法: 1.重启系统,使用windows2008r2安装光盘引导 按住shift+f10 2.切换到d:windows\system32目录(使用cmd. ...

  8. 使用FreeSWITCH做电话自动回访设置

    一.背景介绍: 目前公司在处理客户回访方面,需要人工进行电话回访,尤其是逢年过节的时候,电话问候更能体现服务的品质: 在某些公司,电话销售员需要给大批量的陌生用户打电话,如果能过滤掉不关心的用户,销售 ...

  9. .net下web页生产一维条形码

    code-39 前台 aspx <asp:Image ID="imgBandCode" runat="server" ImageUrl="~/W ...

  10. 输入年月日判断是当年第几天(if判断)