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 jzxy at 2007-09-26 08:04:48 on Problem 1543
#include<stdio.h>
#define N 102
long int a[N], b[N][N];
long int n, p;
void init()
{
	int i;
	for (i = 1; i < N; i++)
	{
		a[i]=i*i*i;
	}
}
void sort(long int start,long int end)
{
	long int i,j,temp;
	for ( i = start; i < end ; i++)
	{
		for ( j = start; j < end-i; j++)
		{
			if ( b[j][0]>b[j+1][0] || b[j][0]==b[j+1][0]&&b[j][1]>b[j+1][1])
				//||b[j][1]==b[j+1][1]&&b[j][2]>b[j+1][2]
				//||b[j][2]==b[j+1][2]&&b[j][3]>b[j+1][3])
			{
				temp = b[j][0];
				b[j][0] = b[j+1][0];
				b[j+1][0] = temp;
				temp = b[j][1];
				b[j][1] = b[j+1][1];
				b[j+1][1] = temp;
				temp = b[j][2];
				b[j][2] = b[j+1][2];
				b[j+1][2] = temp;
				temp = b[j][3];
				b[j][3] = b[j+1][3];
				b[j+16][3] = temp;
			}
		}
	}
}					
int main()
{
	long int i, j, k, h, m, t;
	init();
	/*for (i = 2; i < N; i++)
	printf("a[%d] = %ld\n", i, a[i]);*/
	scanf ("%ld", &n);		
	m = n * n * n;
	for (i = 2; i < N; i++)
	{
		if ( m < a[i] )
		{
			p=i;
			break;
		}
	}
	
	t=0;
	for ( i = 2; i < p; i++)
	{
		for ( j = i; j < p; j++)
		{
			for ( k = j; k < p; k++)
			{
				for ( h = k; h < p; h++)
				{
					if ( a[i] + a[j] + a[k] == a[h] )
					{
						//printf( "i=%ld j=%ld k=%ld h=%ld\n", i, j, k, h);
						b[t][0]=h;
						b[t][1]=i;
						b[t][2]=j;
						b[t++][3]=k;
						break;
					}
				}
			}
		}
	}
	if(t==0)
		return 0;
	else
	{
		sort( 0, t-1);
		for ( i = 0; i < t; i++)
		{
			printf("Cube = %ld, Triple = (%ld,%ld,%ld)\n", b[i][0], b[i][1], b[i][2], b[i][3]);
		}
	}
	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