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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- Dojo与jQuery综合比较分析
最近一直都在参与项目,无法抽空写些或者看些东西,周末抽了点时间看了下关于Dojo和Jquery的东西,在CSDN上看到一篇两个框架进行对比的文章,感觉写的不错,就拿了过来,没有别的意思,一来想保留下来 ...
- TCP 链接 存在大量 close_wait 等待
大量 close_wait 等待 调整linux下 /etc/sysctl.conf参数,里面设置参数: # net.ipv4.tcp_keepalive_time 然后执行 # sysctl -p
- dos 设置 Windows 网络命令
dos 设置Windows 命令: netsh interface ip set address name="本地连接" source=static addr=172.16.12. ...
- python技巧 python2中的除法结果为0
在python2中执行除法操作如果结果小于1就会返回0 如下面的例子: >>>81/82 0 如果你需要返回"正确的结果 ",有两种方法: 在脚本中引入from ...
- 后端python基础
- DSO windowed optimization 代码 (1)
这里不想解释怎么 marginalize,什么是 First-Estimates Jacobian (FEJ).这里只看看代码,看看Hessian矩阵是怎么构造出来的. 1 优化流程 整个优化过程,也 ...
- SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课
1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...
- Debian & CentOS建立本地iso源
在宿舍搞开发的时候经常遇到有些工具需要安装,没有网络,这时候只能靠mount本地的iso镜像来搞,结果像Debian有3张安装光盘,CentOS有2张光盘,有时候安装包不在第一张光盘里,而在第二张光盘 ...
- session和token
功能是一样的,都是要与浏览器建立连接,获取与客户端对应的用户数据,只不过完成这个功能的实现方式不太一样. 本质上的区别: session的使用方式是客户端cookie里存id,服务端session存用 ...
- windows系统中hosts文件位置
C:\Windows\System32\drivers\etc\hosts 10.0.0.213 mr1.bic.zte.com 10.0.0.2 mr2.bic.zte.com 10.0.0.102 ...