HDU 1250 HDOJ 1250 Hat's Fibonacci ACM 1250 IN HDU
Posted on 2010-10-22 20:41 MiYu 閱讀(833) 評論(0) 編輯 收藏 引用 所屬分類: ACM ( 水題 ) 、ACM ( 大數 )MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=1250
題目描述:
Hat's Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2208 Accepted Submission(s): 684
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
100
4203968145672990846840663646 Note: No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
/*
Mail to : miyubai@gamil.com
MyBlog : baiyun.me
Link : http://www.cnblogs.com/MiYu || http://www.shnenglu.com/MiYu
Author By : MiYu
Test : 1
Complier : g++ mingw32-3.4.2
Program : Hat's Fibonacci
Doc Name : HDU_1250
*/
/*
高精度的水題 , JAVA 水過, 當然 用模板也一樣
*/
package main;
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner ( System.in );
while ( cin.hasNext() ) {
int N = cin.nextInt();
if ( N <= 4 ) {
System.out.println ( 1 );
} else {
BigInteger one = new BigInteger ( "1" );
BigInteger two = new BigInteger ( "1" );
BigInteger three = new BigInteger ( "1" );
BigInteger four = new BigInteger ( "1" );
BigInteger res = new BigInteger ( "1" );
BigInteger temp = new BigInteger ( "1" );
for ( int i = 4; i < N; ++ i ) {
res = one.add(two).add(three).add(four);
temp = res;
one= two;
two = three;
three = four;
four = temp;
}
System.out.println( res );
}
}
}
}