hdu 1329 Hanoi Tower Troubles Again!

找规律的题目an=an-1+(i+i%2)/2*2;

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;
int
main()
{

    int
i,j,ans[51];
    ans[1]=1;
    for
(i=2;i<=50;i++)
    {

        ans[i]=ans[i-1]+(i+i%2)/2*2;
    }

    int
n,t;
    cin>>t;
    while
(t--)
    {

        cin>>n;
        cout<<ans[n]<<endl;
    }

    return
0;
}

你可能感兴趣的:(HDU)