2009-04-15 21:40:50來源不明
長壽的兔子
該死的兔子
害我找了半天...因為我是廢物吧 哈哈
遞迴
找出其中的關係!!
/***********************************************************/
#include<stdio.h>
#include<stdlib.h>
main()
{
unsigned long long int math[101]={0},m[101]={0};
int a,b,n;
math[11]=2;m[11]=2;
for(a=12;a<=100;a++)
{
m[a]=m[a-1]*2;
math[a]+=m[a]+math[a-1];
}
while(scanf("%d",&n)==1)
printf("%llu\n",math[n+11]-math[n+1]);
return 0;
}
/*
2 6 14 30 62 126 254 510 1022 2046 4092 8184
2 4 8 16 32 64 128 256 512 1024 2048 4096
*/
這是我的方法 你的解法好特別 0.0
想必是太常用陣列解題了XD
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long unsigned n, i, sum, temp;
while(cin >> n) {
sum = 2, temp = 2;
for(i = 1; i <= n; i++) {
temp *= 2;
sum += temp;
if (i >= 10) {
sum -= (long long unsigned)pow(2, (i-9));
}
}
cout << sum << endl;
}
return 0;
}
感謝分享程式碼押 2009-05-12 22:00:36