Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请问这个题除了暴力有没有好的算法呢?弱鸡求大佬帮助QAQ

Posted by iwts at 2017-10-29 09:42:55 on Problem 1406
下面是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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator