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

有为高手能帮忙看看我的代码哪里错了吗,谢谢了,老是WRONG ANSWER!!!

Posted by parire at 2009-08-13 16:46:10 on Problem 1067
#include <stdio.h>
#include <math.h>

const double A = 1 + (sqrt(5.0) - 1) / 2;
const double B = 1 + 2 / (sqrt(5.0) - 1);
unsigned long result[3];
unsigned short i;

bool Check(const unsigned long m, const unsigned long n);
void GetResult(const unsigned long m, const unsigned long n);
void Show();

int main()
{
	unsigned long a, b;
	
	//得到a, b值,然后进行计算
	for (i=0;i<3;i++)
	{
		do 
		{
			scanf("%d%d", &a, &b);
		} while (!Check(a, b));

		if (0 == a || 0 == b)
		{
			result[i] = 1;
		} 
		else
		{
			GetResult(a, b);
		}
	}

	//显示结果
	Show();
	
	return 0;
}

bool Check(const unsigned long m, const unsigned long n)
{
	if (m > 1000000000 || n > 1000000000 || m < 0 || n < 0) return false;
	else return true;
}

void GetResult(const unsigned long m, const unsigned long n)
{
	unsigned long r = 0;
	while (A * r - m < 0)
	{
		r++;
	}
	if (m == (int)(A * r))
	{
		if (n == (int)(B * r))
		{
			result[i] = 0;
		} 
		else
		{
			result[i] = 1;
		}
	} 
	else
	{
		r = 0;
		while (B * r - m < 0)
		{
			r++;
		}
		if (n == (int)(A * r)) result[i] = 0;
		else result[i] = 1;
	}
}

void Show()
{
	printf("%d\n%d\n%d\n", result[0], result[1], result[2]);
}

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