-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate_X.cpp
More file actions
59 lines (52 loc) · 910 Bytes
/
evaluate_X.cpp
File metadata and controls
59 lines (52 loc) · 910 Bytes
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
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
#define PI 3.1415926
int set_count(int n)
{
const int MAX = 100000;
int arr[10000];
int flag = 1, i = 0;
while (flag)
{
arr[i] = int(rand() % n);
for (int j = 0; j < i; j++)
if (arr[i] == arr[j])
flag = 0;
i++;
}
return i;
}
int evaluate_n(int n)
{
int count = 0, tem = 0;
//每个集合随机估计10次,求平均值
for (int i = 0; i < 10; i++)
{
tem = set_count(n);
count += 2 * tem*tem / PI;
}
count /= 10;
return count;
}
void main1()
{
srand((unsigned)time(NULL));
//int n=1000, i = 0;
//int count = 0,tem=0;
//for (i=0; i < 10; i++)
//{
// tem = set_count(n);
// count += 2 * tem*tem / PI;
//}
//count /= 10;
//cout << count << endl;
int n = 100;
for (int i = 0; i < 3; i++)
{
cout << "当n=" << n << "时,估计集合的势:" << evaluate_n(n) << endl;
n = n * 10;
}
system("pause");
}