Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这个是怎么回事啊?

Posted by Serendo at 2010-03-09 15:58:29 on Problem 3070
#include <iostream>
#define N 100000
using namespace std;

int Fdata[N]={0,1,1,2};


int fib(int n)
{
    int tmp1,tmp2;//////用G++把这个放在全局变量里就会很诡异,tmp2会覆盖tmp2。
    if(n<N&&Fdata[n]!=0)
        return Fdata[n];
    if(n==0)
        return 0;
    if(n%2==0)
    {
        tmp1=(fib(n/2-1)+fib(n/2+1))*fib(n/2);
        tmp1%=10000;
    }
    else
    {
        tmp1=fib((n+1)/2);
        tmp2=fib((n-1)/2);
        if(tmp1==tmp2)
            cout<<"what!"<<endl;
        tmp1=tmp1*tmp1+tmp2*tmp2;
        tmp1%=10000;
    }
    if(n<N)Fdata[n]=tmp1;

    return tmp1;
}


int main()
{
    int n;
    while(cin>>n)
    {
        if(n==-1)break;
        cout<<fib(n)<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator