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

水题纪念,不过还是用一位老兄说的算法过的

Posted by fany at 2008-08-08 01:30:32 on Problem 1543
把2-100的立方都放到一个数组里面去遍历,这样做不会超时.
#include<iostream>
using namespace std;
int main()
{ 	int n,i,j,p,q,a[101];
    cin>>n;
	for(i=2;i<=100;i++)
	{a[i]=i*i*i;
	}//得到2-100的三次放数
	for(i=2;i<=n;i++)
		for(j=2;j<=n;j++)
			for(p=2;p<=n;p++)
				for(q=2;q<=n;q++)
				{	if(a[i]==a[j]+a[p]+a[q] &&a[j]<a[p] &&a[p]<a[q] &&a[q]<a[i])
						cout<<"Cube = "<<i<<", Triple = ("<<j<<","<<p<<","<<q<<")"<<endl;
				}
   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