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

为什么wa,帮帮我

Posted by westboy at 2006-03-26 16:23:15 on Problem 1491
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int havecf(int a,int b){
	int yu;
	while(yu=a%b){
		a=b;
		b=yu;
	}
	if(b==1)
		return 0;
	else
		return 1;
	
}

double findpi(int array[],int n){

	int cf=0,all,j,k;
	for(j=0;j<n-1;j++){
		for(k=j+1;k<n;k++){
			if(*(array+j)==*(array+k)&&*(array+j)!=1)
				cf++;
			else if(*(array+j)>*(array+k)){
				if(havecf(*(array+j),*(array+k)))
					cf++;
			}
			else if(*(array+j)<*(array+k)){
				if(havecf(*(array+k),*(array+j)))
					cf++;
			}
			else
				continue;
		}
	}

	all=(n*(n-1))/2;
	if(cf==all)
		return -1;
	else
		return sqrt(all*6/(all-cf));
	
}


int main(){
	int n,*array,i;
	double pi;
	scanf("%d",&n);
	while(n!=0){
		array=(int*)malloc(n*sizeof(int));
		for(i=0;i<n;i++)
			scanf("%d",array+i);
		pi=findpi(array,n);
		if(pi==-1)
			printf("No estimate for this data set.\n");
		else
			printf("%.6lf\n",pi);
		
		free(array);
		scanf("%d",&n);
			
	}
	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