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 |
请问这个题除了暴力有没有好的算法呢?弱鸡求大佬帮助QAQ下面是32ms的暴力比较代码。。。 #include<iostream> using namespace std; int main() { int n; cin >> n; while (n) { int a, b; int sum = 0; for (a = 0;; a++) { for (b = 0;; b++) { int temp = a*a*a + (b*(b + 1)*(b + 2)) / 6; if (temp > n) { break; }else { sum = sum > temp ? sum : temp; } } if (a*a*a > n) { break; } } cout << sum << endl; cin >> 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