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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- bzoj1477: 青蛙的约会(exgcd)
昨天打code+的时候发现自己已经不大会exgcd了..赶紧复习一下QAQ 求$ax+by=gcd(a,b)$的解 初始条件 $gcd(a, 0)=a$ $x=1,y=0$ 推导过程 $gcd(a,b ...
- HDU 2191 - 单调队列优化多重背包
题目: 传送门呀传送门~ Problem Description 急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种 ...
- 快速创建SpringBoot2.x应用之工具类自动创建web应用、SpringBoot2.x的依赖默认Maven版本
快速创建SpringBoot2.x应用之工具类自动创建web应用简介:使用构建工具自动生成项目基本架构 1.工具自动创建:http://start.spring.io/ 2.访问地址:http://l ...
- java删除文件及其目录
1.删除指定文件路径 public @ResponseBody String deleteFiles(HttpServletRequest request) { log.info(this.getCl ...
- Django开发笔记一
Django开发笔记一 Django开发笔记二 Django开发笔记三 Django开发笔记四 Django开发笔记五 Django开发笔记六 1.运行 python manage.py runser ...
- Mac下的开发工具
1.webstrom 淘宝上2块钱就能买一个 WebStorm 是jetbrains公司旗下一款JavaScript 开发工具.被广大中国JS开发者誉为“Web前端开发神器”.“最强大的HTML5编辑 ...
- 【.net】获取网页CDM的下载链接的地址
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServi ...
- C/C++:函数调用规则__stdcall,__cdecl,__pascal,__fastcall
__cdecl __cdecl 是 C Declaration 的缩写,表示 C 语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈.被调用函数不会要求调用者传递多 ...
- P3567 [POI2014]KUR-Couriers
题目描述 Byteasar works for the BAJ company, which sells computer games. The BAJ company cooperates with ...
- 容器平台选型的十大模式:Docker、DC/OS、K8S 谁与当先?【转】
网易企业服务2017-10-13 无论是在社区,还是在同客户交流的过程中,总会被问到到底什么时候该用 Docker?什么时候用虚拟机?如果使用容器,应该使用哪个容器平台? 显而易见,我不会直接给大家一 ...