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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- spring注解第07课 @Valid和@Validated的总结区分
@Valid: @Valid注解用于校验,所属包为:javax.validation.Valid. ① 首先需要在实体类的相应字段上添加用于充当校验条件的注解,如:@Min,如下代码(age属于Gir ...
- Java——分页 Servlet + Jsp+Jdbc 有点瑕疵
1.创建数据库,插入多条数据 2.java连接DB 3.Person类: package com.phome.po; public class Person { private int id; pri ...
- History API:ScrollRestoration
By Paul Lewis(设计和性能倡导者) 翻译:江天 使用history api管理url是非常棒的一件事,可以说这是一个好web app的极为重要的特点.但它有一个缺点,滚动位置虽然被存储 ...
- mysql 查询优化 ~explain解读之type的解读
一 简介:今天咱们来聊聊explain中type的相关解读 二 类型: system: 表中只有一条数据. 这个类型是特殊的 const 类型. const: 针对主键或唯一索引的等值查询扫描, 最 ...
- HTTP协议-响应报文格式
HTTP协议-响应码 浏览器向服务器发出请求,服务器处理可能是成功.可能是失败.可能没有权限访问等原因,服务器会通过响应码来告诉浏览器处理结果. " : OK " : Found ...
- ProcessHacker可编译版本
说明 做一个批量进程内搜索字符串的工具. 试了processhacker-2.39-src.zip. https://sourceforge.net/projects/processhacker/fi ...
- 文件&报表状态ID
def_filestatus Uploading=4 WaitingParse=6 Parsing=10 Completed=14 ParseError=1006 UploadError=1004 d ...
- Linux下svn常用指令【转】
转自:http://blog.csdn.net/myarrow/article/details/8110858 Windows下的TortoiseSVN是资源管理器的一个插件,以覆盖图标表示文件状态, ...
- UART中的硬件流控RTS与CTS DTR DSR DTE设备和DCE设备【转】
中低端路由器上使用disp interface 查看相应串口状态信息,其中DCD.DTR.DSR.RTS及CTS等五个状态指示分别代表什么意思? DCD ( Data Carrier Detect 数 ...
- html5 postMessage解决跨域、跨窗口消息传递(转)
仅做学习使用,原文链接:http://www.cnblogs.com/dolphinX/p/3464056.html 一些麻烦事儿 平时做web开发的时候关于消息传递,除了客户端与服务器传值还有几个经 ...