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

难道是所有的TEST CASE算1000MS,我的对于单独的我都测了,貌似不会超时。

Posted by yogafrank at 2008-08-27 22:43:49 on Problem 2042
除非是所有的TEST CASE算一次时间。。。
用的是暴力。。。

#include <iostream>
using namespace std;

int ways;

void process ( int v )
{
	int i, j, m, n, a, b, c, d;

	for ( i = 0, a = i * i; i <= 512; i++, a = i * i )
	{
		if ( a > v )
			break;

		for ( j = i, b = j * j; j <= 512; j++, b = j * j )
		{
			if ( a + b > v )
				break;

			for ( m = j, c = m * m; m <= 512; m++, c = m * m )
			{
				if ( a + b + c > v )
					break;

				for ( n = m, d = n * n; n <= 512; n++, d = n * n )
				{
					if ( a + b + c + d > v )
						break;
					if ( a + b + c + d == v )
						ways++;
				}
			}
		}
	}
}

int main ()
{
	int n;

	while ( cin >> n )
	{
		if ( n == 0 )
			break;

		ways = 0;
		process ( n );
		cout << ways << 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