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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

基础编程题之牛客网星际密码

發(fā)布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基础编程题之牛客网星际密码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • 題目
  • 解題思路
  • 代碼

題目

???br />

解題思路

本題的基本意思就是給你給定一個矩陣:(1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?),然后一個數(shù)n,n表示矩陣(1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?)的n次方,這個n代表一個數(shù)也就是解密的結(jié)果,即為(1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?)n的結(jié)果的(也是一個矩陣)的左上角數(shù)字。
如果該數(shù)字小于4就用0補充,如果大于4就只輸出最后4位

同時矩陣的乘法公式如下:

所以先代入前幾個數(shù),可以發(fā)現(xiàn)如下規(guī)律

當(dāng)n=1時,左上角值=1

(1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?)

當(dāng)n=2時,左上角值=2

(1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?) * (1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?) =(1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?)

當(dāng)n=3時,左上角值=3

(2111)\begin{pmatrix} 2 & 1 \\ 1 & 1 \end{pmatrix}(21?11?) * (1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?) = (3221)\begin{pmatrix} 3 & 2 \\ 2 & 1 \end{pmatrix}(32?21?)

當(dāng)n=4時,左上角值=4

(3221)\begin{pmatrix} 3 & 2 \\ 2 & 1 \end{pmatrix}(32?21?) * (1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?) = (5332)\begin{pmatrix} 5 & 3 \\ 3 & 2 \end{pmatrix}(53?32?)

當(dāng)n=5時,左上角的值=8

(5332)\begin{pmatrix} 5 & 3 \\ 3 & 2 \end{pmatrix}(53?32?) * (1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}(11?10?) = (8553)\begin{pmatrix} 8 & 5 \\ 5 & 3 \end{pmatrix}(85?53?)

當(dāng)n=6時,左上角的值=?

····
····
····

可以發(fā)現(xiàn)是很明顯的斐波那契數(shù)列

代碼

// write your code here cpp #include <iostream> #include <vector> #include <cstdio> using namespace std;void Fib(vector<int>& fib) {for(int i=2 ;i < 10001;i++){fib.push_back((fib[i-1]+fib[i-2])%10000);} } int main() {int number=0;//數(shù)據(jù)個數(shù)vector<int> fib={1,1};//斐波那契數(shù)列Fib(fib);//初始化while(cin >> number){int temp;while(number--){cin >> temp;printf("%04d",fib[temp]);}cout<<endl;}return 0; }

總結(jié)

以上是生活随笔為你收集整理的基础编程题之牛客网星际密码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。