-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathratsphere.txt
74 lines (74 loc) · 1.53 KB
/
ratsphere.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define PI 3.1415926
#define dbl double
dbl fn[100005];
dbl save[100005];
int main(){
dbl rad;
int i,j;
dbl count = 0.00,x,y,z;
dbl rats[3];
dbl cats[3],fl=0;
rep:
fprintf(stderr,"R??");
scanf("%lf",&rad);
dbl range = rad/10;
srand(time(0));
for(i=0;i<10000;i++){
rats[0] = -rad;
rats[1] = rats[2] = cats[1] = 0;
cats[0] = rad;
cats[2] = 1;
fprintf(stderr,"%d\n",i);
for(j=1;j<=10000;j++){
int flag=0;
do{
dbl theta = (dbl)rand()/(dbl)RAND_MAX;
theta*=PI;
dbl phi = (dbl)rand()/(dbl)RAND_MAX;
phi*=2*PI;
x = cos(theta);
y = sin(theta) * cos(phi);
z = sin(theta) * sin(phi);
if(sqrt(pow(rats[0]+x,2) + pow(rats[1]+y,2) + pow(rats[2]+z,2)) <= rad){
flag=1;
rats[0]+=x;
rats[1]+=y;
rats[2]+=z;
}
}
while(flag==0);
flag=0;
do{
dbl theta = (dbl)rand()/(dbl)RAND_MAX;
theta*=PI;
dbl phi = (dbl)rand()/(dbl)RAND_MAX;
phi*=2*PI;
x = cos(theta);
y = sin(theta) * cos(phi);
z = sin(theta) * sin(phi);
if(sqrt(pow(cats[0]+x,2) + pow(cats[1]+y,2) + pow(cats[2]+z,2)) <= rad){
flag=1;
cats[0]+=x;
cats[1]+=y;
cats[2]+=z;
}
}
while(flag==0);
if(sqrt(pow(cats[0]-rats[0],2) + pow(cats[1]-rats[1],2) +pow(cats[3]-rats[3],2)) < range) break;
else if(fl==0) fn[j]+=1.0;
else save[j]+=1.0;
}
}
if(fl==0){
fl=1;
goto rep;
}
for(i=1;i<=10000;i++){
printf("%d %lf %lf\n",i,(dbl)(fn[i]/10000.00),(dbl)(save[i]/10000.00));
}
return 0;
}