题意:

一直TLE我也是醉了,,不爽!

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define MAXN 100005
#define INF 0x3f3f3f3f
#define MAXN 100005
#define eps 1e-8
using namespace std;
LL ax, ay, bx, by, cx, cy, kx, ky, nx, ny, x, p;
struct Martix
{
LL m[][];
Martix()
{
memset(m, , sizeof(m));
}
};
void m_quick_power(Martix &a, Martix &b)
{
Martix c;
for(int i = ; i <= ; i++){
for(int j = ; j <= ; j++){
for(int k = ; k <= ; k++){
c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % p;
}
}
}
a = c;
}
LL work(int s, LL n)
{
Martix u, v;
u.m[][] = ax, u.m[][] = bx, u.m[][] = cx, u.m[][] = s;
v.m[][] = v.m[][] = v.m[][] = v.m[][] = v.m[][] = , v.m[][] = v.m[][] = kx;
while(n){
if(n & ){
m_quick_power(u, v);
}
m_quick_power(v, v);
n >>= ;
}
return u.m[][];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int T;
scanf("%d", &T);
while(T--){
scanf("%I64d", &p);
scanf("%I64d%I64d%I64d%I64d%I64d", &ax, &bx, &cx, &kx, &nx);
scanf("%I64d%I64d%I64d%I64d%I64d", &ay, &by, &cy, &ky, &ny);
scanf("%I64d", &x);
nx--;
ny--;
int cnt = ;
int j = ;
for(int i = ; i <= p; i++){
if(work(i, nx) == x){
cnt++;
j = i;
}
}
if(cnt != ){
printf("UNKNOWN\n");
continue;
}
ax = ay, bx = by, cx = cy, kx = ky;
LL ans = work(j, ny) % p;
printf("%I64d\n", ans);
}
}

Gym - 100625E Encoded Coordinates 矩阵快速幂的更多相关文章

  1. CodeChef-----February Challenge 2018---Broken Clock(极坐标+三角函数递推+矩阵快速幂)

    链接:  https://www.codechef.com/FEB18/problems/BROCLK Broken Clock Problem Code: BROCLK Chef has a clo ...

  2. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  3. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  4. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  5. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

  6. HDU5950(矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...

  7. 51nod 1126 矩阵快速幂 水

    有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输 ...

  8. hdu2604(递推,矩阵快速幂)

    题目链接:hdu2604 这题重要的递推公式,找到公式就很easy了(这道题和hdu1757(题解)类似,只是这道题需要自己推公式) 可以直接找规律,推出递推公式,也有另一种找递推公式的方法:(PS: ...

  9. 矩阵乘法&矩阵快速幂&矩阵快速幂解决线性递推式

    矩阵乘法,顾名思义矩阵与矩阵相乘, 两矩阵可相乘的前提:第一个矩阵的行与第二个矩阵的列相等 相乘原则: a b     *     A B   =   a*A+b*C  a*c+b*D c d     ...

随机推荐

  1. 【jQuery04】折叠树

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. django 之数据库模块

    前提ajango的 数据库主要是为了存取网站的一些内容,数据库的设置一般放在model.py 下   目录下 我们设置如下的数据库:具体的代码如下面所示: # -*- coding: utf-8 -* ...

  3. URAL 2027 2028 两个有趣的题

    这两个题,讲的是有一种奇怪的语言,代码是一种二维的矩阵. 前一个题,是根据所给的要求,写一个简单的解释器. 后一个题,是用那种语言写一个简单的小程序. 挺有意思的,所以在这里纪念一下.顺便那个语言的原 ...

  4. Oracle单实例情况下的library cache pin的问题模拟与问题分析

    Oracle单实例情况下的library cache pin的问题模拟与问题分析 參考自: WAITEVENT: "library cache pin" Reference Not ...

  5. hdu_1698线段树成段更新

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...

  6. FZOJ--2221-- RunningMan(水题)

    Problem 2221 RunningMan Accept: 4    Submit: 10 Time Limit: 1000 mSec    Memory Limit : 32768 KB Pro ...

  7. hdoj--1556--Color the ball(模拟&&树状数组)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. windows下git的安装和使用

    git到底是个什么东西,我这里就不介绍了,如果大家还有不懂的,可以去百度一下的.我这里给一个介绍的网址:git简介        这里在留一个地址http://baike.baidu.com/subv ...

  9. [POJ2728] Desert King 解题报告(最优比率生成树)

    题目描述: David the Great has just become the king of a desert country. To win the respect of his people ...

  10. dedecms实现表单提交数据到指定的邮箱

    1.http://blog.csdn.net/webnoties/article/details/17219219 2.http://www.jz96.com/451.html 3.https://m ...