Mistwald POJ
一开始看不出来是快速幂矩阵的题目
先要把整个地图离散化为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的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- 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 ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- Visual Studio 各版本下载
http://baike.baidu.com/link?url=guN2bFtq-TvtdH-iDSiYFDJ-HF8R4_12qz6QRjxKxP2Nz8jK0p70KlmudolZOg-C3umq ...
- C# 使用ffmpeg视频截图
<appSettings> <add key="ffmpeg" value="E:\ffmpeg\ffmpeg-20141012-git-20df026 ...
- CF28D Don't fear, DravDe is kind
传送门 题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求 ...
- python队列queue 之优先级队列
import queue as Q def PriorityQueue_int(): que = Q.PriorityQueue() que.put(10) que.put(1) que.put(5) ...
- proxysql 系列~审核功能
一 简介:今天我们来探讨下具体的审核功能 二 平台审计功能 一 proxysql 设置 set mysql-eventslog_filename = '/data/ProxySQL/log/sql. ...
- PMM安装-第一篇
一 简介 今天来聊聊 PMM安装使用 二 安装 1 server端执行 curl -sSL https://get.daocloud.io/docker | sh docker pull p ...
- python - class类 (一)
三大编程范式 1.面向过程 2.函数式 3.面向对象 注意 编程范式没有高低之分,只有适用不适用. 面向对象编程: 编程是程序源用特定的语法+数据结构+算法组成的代码来告诉计算机如何执行任务的过程,一 ...
- XMLHttpRequest: 网络错误 0x2f78,…00002f78
常在河边走,怎能不湿脚,在web前端开发的过程中总是遇到很多关于IE的故事. 一个get请求,传了一个json对象,包含一串参数,在IE上就出现了这个问题:XMLHttpRequest: 网络错误 0 ...
- Linux MMC framework2:基本组件之host
声明:本文很多内容和思路参考了http://www.wowotech.net/comm/mmc_host_driver.html,对原作者表示感谢! 1.前言 本文是Linux MMC framewo ...
- nodejs的 new String
已知rwo4的记录中baitaiid是001// row4为jhlist开始循环结果 for(var i=0;i<row4.length;i++) { var baiTaiId=new Stri ...