首页 > 其他 > 详细

Ural1225(数学)

时间:2015-03-05 14:52:16      阅读:193      评论:0      收藏:0      [点我收藏+]

题目链接:点击打开链接


解题思路:

上来先把n 分别为1、2、3、4的情况大致列了一下,发现n == 1时结果为2,n== 2时结果为2,n == 3时结果为4,n== 4时结果为6.

于是大胆的猜想ans[i] = ans[i - 1] + ans[i - 2],但是WA在#12。把预处理表打出来看了看······当n达到45时,结果都溢出了,并且此题long long存不下,果断开unsigned long long。


完整代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
int n;
const int maxn = 55;
unsigned long long ans[maxn];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ans[1] = ans[2] = 2;
    for(int i = 3; i < maxn ; i ++)
        ans[i] = ans[i - 1] + ans[i - 2];
    while(cin >> n)
    {
        cout << ans[n] << endl;
    }
}

更多精彩请访问:点击打开链接

Ural1225(数学)

原文:http://blog.csdn.net/u013447865/article/details/44081271

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!