| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么wa,帮帮我#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator