1. 程式人生 > >HDOJ_2047_阿牛的EOF牛肉串

HDOJ_2047_阿牛的EOF牛肉串

AC程式碼:

#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
    freopen("in.txt","r",stdin);
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        long long sum1,sum2,sum;
        sum1=3;
        sum2=8;
        if(n==1)
            sum=sum1;
        else
if(n==2) sum=sum2; else for(int i=3;i<=n;i++) { sum=2*sum2+2*sum1; sum1=sum2; sum2=sum; } printf("%lld\n",sum); } fclose(stdin); return 0; }