Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
从过1338的大牛那里学到的解法... 很牛叉,直接水过(附上代码)#include<stdio.h> #define Min(a, b) ((a)<(b)?(a):(b)) #define N 10000001 long f[N]; int main() { int n,i; int x_2 = 1,x_3 = 1; f[x_2] = 1; f[x_3] = 1; for(i=2; i<=10000000; i++) { f[i] = Min(f[x_2]*2+1, f[x_3]*3+1); if(f[i] == f[x_2]*2+1) x_2++; if(f[i] == f[x_3]*3+1) x_3++; } while(scanf("%d",&n) != EOF) { printf("%ld\n",f[n]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator