日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Gym - 100625E Encoded Coordinates 矩阵快速幂

發布時間:2025/7/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Gym - 100625E Encoded Coordinates 矩阵快速幂 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

一直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 long 15 #define MAXN 100005 16 #define INF 0x3f3f3f3f 17 #define MAXN 100005 18 #define eps 1e-8 19 using namespace std; 20 LL ax, ay, bx, by, cx, cy, kx, ky, nx, ny, x, p; 21 struct Martix 22 { 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_JUDGE 58 freopen("in.txt", "r", stdin); 59 //freopen("out.txt", "w", stdout); 60 #endif // OPEN_FILE 61 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 }

?

轉載于:https://www.cnblogs.com/macinchang/p/4723152.html

總結

以上是生活随笔為你收集整理的Gym - 100625E Encoded Coordinates 矩阵快速幂的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。