2019第十届蓝桥杯C/C++ A组省赛 —— 第二题: 数列求值
生活随笔
收集整理的這篇文章主要介紹了
2019第十届蓝桥杯C/C++ A组省赛 —— 第二题: 数列求值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
試題 B: 數列求值
本題總分:5 分
【問題描述】
給定數列 1, 1, 1, 3, 5, 9, 17, …,從第 4 項開始,每項都是前 3 項的和。求
第 20190324 項的最后 4 位數字。
【答案提交】
這是一道結果填空的題,你只需要算出結果后提交即可。本題的結果為一個 4 位整數(提示:答案的千位不為 0),在提交答案時只填寫這個整數,填寫多余的內容將無法得分。
Code
/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^0. ^ 0^.0 1 .^.1 ^0 .........001^.1 1. .111100....01^00 11^ ^1. .1^1.^ ^0 0^.^ ^0..1.1 1..^1 .0 ^ ^00. ^^0.^^ 0 ^^110.^0 0 ^ ^^^10.01^^ 10 1 1 ^^^1110.101 10 1.1 ^^^1111110010 01 ^^ ^^^1111^1.^ ^^^10 10^ 0^ 1 ^^111^^^0.1^ 1....^11 0 ^^11^^^ 0.. ....1^ ^ ^1. 0^ ^11^^^ ^ 1 111^ ^ 0.10 00 11 ^^^^^ 1 0 1.0^ ^0 ^0 ^^^^ 0 0.0^ 1.0 .^ ^^^^ 1 1 .0^.^ ^^ 0^ ^1 ^^^^ 0. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 1001 ^^ ^^^ . 1^. ^ ^. 11 0. 1 ^ ^^ 0.0 ^. 0 ^0 1 ^^^ 0.0.^ 1. 0^ 0 .1 ^^^ ...1 1. 00 . .1 ^^^ ..1 1. ^. 0 .^ ^^ ..0. 1. .^ . 0 ..1 1. 01 . . ^ 0^.^ 00 ^0 1. ^ 1 1.0 00 . ^^^^^^ ..^ 00 01 ..1. 00 10 1 ^^.1 00 ^. ^^^ .1.. 00 .1 1..01 ..1.1 00 1. ..^ 10^ 1^ 00 ^.1 0 1 1.1 00 00 ^ 1 ^. 00 ^.^ 10^ ^^1.1 00 00 10^..^ 1. ^. 1.0 1 ^. 00 00 .^^ ^. ^ 1 00 ^0000^ ^ 011 0 ^. 00.0^ ^00000 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 1. .^1. 1 1. ^0^ . ^.1 00 01^.0 001. .^*//* Procedural objectives:Variables required by the program:Procedural thinking:Functions required by the program:Determination algorithm:Determining data structure:*/ /* My dear Max said: "I like you, So the first bunch of sunshine I saw in the morning is you, The first gentle breeze that passed through my ear is you, The first star I see is also you. The world I see is all your shadow."FIGHTING FOR OUR FUTURE!!! */ #include <iostream>using namespace std;long long n,a=1,b=1,c=1,sum=0;long long ans(int num){if(num<4)return 1;else{for(int i=3;i<num;i++){sum=(a+b+c)%10000;a=b;b=c;c=sum;}return sum;} }int main(){ // cin>>n;n=20190324;cout<<ans(n)<<endl;return 0; }總結
以上是生活随笔為你收集整理的2019第十届蓝桥杯C/C++ A组省赛 —— 第二题: 数列求值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2019第十届蓝桥杯C/C++ A组省赛
- 下一篇: 2019第十届蓝桥杯C/C++ A组省赛