NYOJ 698 A Coin Problem (斐波那契)

链接:click here

题意:

描述
One day,Jiameier is tidying up the room,and find some coins. Then she throws the coin to play.Suddenly,she thinks of a problem ,that if throw n times coin ,how many situations of no-continuous up of the coin. Hey,Let‘s solve the
problem.

输入
The first of input is an integer T which stands for the number of test cases. For each test case, there is one integer n (1<=n<=1000000000) in a line, indicate the times of throwing coins.
输出
The number of all situations of no-continuous up of the coin, moduled by 10000.
样例输入
3
1
2
3
样例输出
2
3
5
来源
SCU Programming Contest 2011
Preliminary

思路:大数的斐波那契。

代码:

#include <stdio.h>
int main()
{
    int i;
    int a[15010];
    a[0]=0,a[1]=2,a[2]=3;
    for(i=3;i<15010;i++)
        a[i]=(a[i-1]+a[i-2])%10000;
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int m;
        scanf("%d",&m);
        printf("%d\n",a[m%15000]%10000);
    }
    return 0;
}

When you want to give up, think of why you persist until now!

时间: 2025-01-11 20:51:29

NYOJ 698 A Coin Problem (斐波那契)的相关文章

NYOJ 252 01串(斐波那契数列变形)

01串 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有“11”子串的这种长度的01串共有多少个,他希望你能帮帮他. 注:01串的长度为2时,有3种:00,01,10. 输入 第一行有一个整数n(0<n<=100),表示有n组测试数据;随后有n行,每行有一个整数m(2<=m<=40),表示01串的长度; 输出 输出不含有“11”子串的这种长度的01串共有多少个,占一行. 样例输入 2

NYOJ 461-Fibonacci数列(四)(求斐波那契数列前4位)

题目地址:NYOJ 461 思路:斐波那契数列的通项公式为 然后下一步考虑如何产生前4位: 先看对数的性质,loga(b^c)=c*loga(b),loga(b*c)=loga(b)+loga(c);假设给出一个数10234432, 那么log10(10234432)=log10(1.0234432*10^7)[用科学记数法表示这个数]=log10(1.0234432)+7; log10(1.0234432)就是log10(10234432)的小数部分. log10(1.0234432)=0.0

hdu-5686 Problem B(斐波那契数列)

题目链接: Problem B Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description 度熊面前有一个全是由1构成的字符串,被称为全1序列.你可以合并任意相邻的两个1,从而形成一个新的序列.对于给定的一个全1序列,请计算根据以上方法,可以构成多少种不同的序列. Input 这里包括多组测试数据,每组测试数据包含一个正整数N,代表全1序列的长度.

CF735C 数论\平衡树叶子节点的最大深度\贪心\斐波那契\条件归一化

http://codeforces.com/problemset/problem/735/C 题意..采用淘汰赛制..只要打输就退出比赛..而且只有两个选手打过的场数 相差不超过1才能比赛..最后问你..最多打几场比赛能决出冠军 那么这个题的做法是..画图..观察..分析 Tip:首先我们观察未知量的形式..它是一个复合函数的形式..max(决出冠军的所有可能的比赛方式的场数) 那么我们首先要求括号最里面的东西..即符合条件的所有可能的比赛方式的场数 那么我们可以画一画 我一开始为了保证比赛能正

HDU 4549 M斐波那契数列(矩阵快速幂)

Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的值吗? Input 输入包含多组测试数据: 每组数据占一行,包含3个整数a, b, n( 0 <= a, b, n <= 10^9 ) Output 对每组测试数据请输出一个整数F[n],由于F[n]可能很大,你只需输出F[n]对1000000007取模

ACdreamOJ 1116 斐波那契数列+hash计算后缀

http://acdream.info/problem?pid=1116 Problem Description give you a string, please output the result of the following function mod 1000000007 n is the length of the string f() is the function of fibonacci, f(0) = 0, f(1) = 1... a[i] is the total numb

剑指OFFER之斐波那契数列

题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.斐波那契数列的定义如下: 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1<=n<=70). 输出: 对应每个测试案例, 输出第n项斐波那契数列的值. 样例输入: 3 样例输出: 2 注意:这道题目用递归的话会做大量的重复计算,效率很低.Code: #include <iostream> using namespace std; long long Fibonacc

hdu 4893 Wow! Such Sequence!(线段树功能:单点更新,区间更新相邻较小斐波那契数)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4893 --------------------------------------------------------------------------------------------------------------------------------------------

002. 斐波那契数列中的偶数

Problem 2: Even Fibonacci numbers Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibo