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 wangjild at 2011-10-05 00:19:29 on Problem 1067
float的精度不够,要用double,不然会悲剧的WA



#include <stdio.h>
#include <math.h>

double sq5 = sqrt(5);

int match(int a, int b){
	int j = b - a;
	int aj = floor(j * (sq5 + 1.0)/2.0);
	if(aj == a)
		return 1;
	// printf("j = %d, aj = %d\n", j, aj);
	return 0;
}

#define swap(a, b) \
{ \
	int tm = (a); \
	(a) = (b); \
	(b) = tm; \
}

int main(){
	int a, b;
	while(scanf("%d%d", &a, &b) != EOF){
		if(a > b)
			swap(a, b);
		if(match(a, b)){
			printf("0\n");
		}else{
			printf("1\n");
		}
	}
}

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