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 |
对前面大牛算法的改进In Reply To:以轻易的脚步走掉我的第50题,菜鸟也,任重道远(附代码) Posted by:547880119 at 2009-02-24 18:05:15 #include <iostream> #include <algorithm> using namespace std; int main() { int mul2 = 2,mul3 = 3,mul5 = 5,t = 0; int i = 1,j = 1,k = 1; long result[1500 + 1] = {0}; result[1] = 1; int index = 2; for (;index <= 1500;++index) { t = min(mul2,min(mul3,mul5)); result[index] = t; if (t == mul2) mul2 = result[++i] * 2; if (t == mul3) mul3 = result[++j] * 3; if (t == mul5) mul5 = result[++k] * 5; } while (cin >> index,index > 0) { cout << result[index] << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator