-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathsolve.c
51 lines (44 loc) · 1.25 KB
/
solve.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
double rand01() {
return (double)rand() / RAND_MAX;
}
int main() {
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
int time0 = time(0);
char buf1[100] = "3.13801";
char buf2[100] = "3.14753";
for (int clock0 = 0; clock0 < 2000; clock0++) {
srand((unsigned)time0 + clock0);
int games = 5;
int win = 0;
int lose = 0;
char target[20];
char guess[2000];
for (int i = games; i > 0; i--) {
int M = 0;
int N = 400000;
for (int j = 0; j < N; j++) {
double x = rand01();
double y = rand01();
if (x * x + y * y < 1)
M++;
}
double pi = (double)M / N * 4;
sprintf(target, "%1.5f", pi);
if (i == 5) {
if (strcmp(target, buf1) != 0)
break;
} else if (i == 4) {
if (strcmp(target, buf2) != 0)
break;
} else
printf("clock0 = %d, i = %d, target = %s\n", clock0, i, target);
}
}
return 0;
}