Gym - 100625E Encoded Coordinates 矩阵快速幂
来源:互联网 发布:千万不要相信网络拍卖 编辑:程序博客网 时间:2024/06/01 16:41
题意:
一直TLE我也是醉了,,不爽!
1 #include <iostream> 2 #include <cstdio> 3 #include <fstream> 4 #include <algorithm> 5 #include <cmath> 6 #include <deque> 7 #include <vector> 8 #include <queue> 9 #include <string>10 #include <cstring>11 #include <map>12 #include <stack>13 #include <set>14 #define LL long long15 #define MAXN 10000516 #define INF 0x3f3f3f3f17 #define MAXN 10000518 #define eps 1e-819 using namespace std;20 LL ax, ay, bx, by, cx, cy, kx, ky, nx, ny, x, p;21 struct Martix22 {23 LL m[10][10];24 Martix()25 {26 memset(m, 0, sizeof(m));27 }28 };29 void m_quick_power(Martix &a, Martix &b)30 {31 Martix c;32 for(int i = 1; i <= 5; i++){33 for(int j = 1; j <= 5; j++){34 for(int k = 1; k <= 5; k++){35 c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % p;36 }37 }38 }39 a = c;40 }41 LL work(int s, LL n)42 {43 Martix u, v;44 u.m[1][1] = ax, u.m[1][2] = bx, u.m[1][3] = cx, u.m[1][4] = s;45 v.m[2][1] = v.m[3][1] = v.m[4][2] = v.m[1][3] = v.m[3][4] = 1, v.m[1][2] = v.m[2][3] = kx;46 while(n){47 if(n & 1){48 m_quick_power(u, v);49 }50 m_quick_power(v, v);51 n >>= 1;52 }53 return u.m[1][1];54 }55 int main()56 {57 #ifndef ONLINE_JUDGE58 freopen("in.txt", "r", stdin);59 //freopen("out.txt", "w", stdout);60 #endif // OPEN_FILE61 int T;62 scanf("%d", &T);63 while(T--){64 scanf("%I64d", &p);65 scanf("%I64d%I64d%I64d%I64d%I64d", &ax, &bx, &cx, &kx, &nx);66 scanf("%I64d%I64d%I64d%I64d%I64d", &ay, &by, &cy, &ky, &ny);67 scanf("%I64d", &x);68 nx--;69 ny--;70 int cnt = 0;71 int j = 0;72 for(int i = 1; i <= p; i++){73 if(work(i, nx) == x){74 cnt++;75 j = i;76 }77 }78 if(cnt != 1){79 printf("UNKNOWN\n");80 continue;81 }82 ax = ay, bx = by, cx = cy, kx = ky;83 LL ans = work(j, ny) % p;84 printf("%I64d\n", ans);85 }86 }
0 0
- Gym - 100625E Encoded Coordinates 矩阵快速幂
- Sicily 14180. Encoded Coordinates
- 矩阵快速幂——RGB plants (Gym 101061 B)
- Codeforces Gym 101061 B RGB plants(矩阵快速幂)
- GYM 100827 F.Knights(dp+矩阵快速幂)
- GYM 101061 B.RGB plants(dp+矩阵快速幂)
- GYM 101061 G.Repeat it(dp+矩阵快速幂)
- gym 101061-B RGB plants 裸矩阵快速幂
- 514E (矩阵快速幂+DP)
- Codeforces 514E 矩阵快速幂
- E. Lost in WHU。矩阵快速幂!
- 2014北京邀请赛E题-矩阵快速幂
- 2014北京邀请赛E题-矩阵快速幂
- ASC(1)E(矩阵快速幂+简单DP)
- Codeforces 691E Xor-sequences【矩阵快速幂,好题】
- Codeforces 691E Xor-sequences(矩阵快速幂)
- Codeforces 691 E Xor-sequences 矩阵快速幂
- CodeForces-691E Xor-sequences(矩阵快速幂)
- jmeter学习 十三 内置函数
- Gym - 100625J Jailbreak 最短路+搜索
- Gym - 100625G Getting Through 计算几何+并查集
- 串口通信参数
- Gym - 100625D Destination Unknown 最短路
- Gym - 100625E Encoded Coordinates 矩阵快速幂
- 我们一起学python-helloworld2
- Yii2 framework学习笔记(三) -- 语言与国际化
- 生活感受
- 查找字符串中对应的字符并返回数组位置
- Gym - 100625B Bribe
- WEB API 使用空间数据类型 发布出错
- HDU 5375 Gray Code 动归
- hihocoder 1108 : Troublesome Power Supply