forked from whai362/AcmCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp.cpp
More file actions
89 lines (80 loc) · 1.6 KB
/
tmp.cpp
File metadata and controls
89 lines (80 loc) · 1.6 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*======================================================
# Author: whai
# Last modified: 2015-12-18 19:40
# Filename: tmp.cpp
======================================================*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
using namespace std;
#define LL __int64
#define PB push_back
#define P pair<int, int>
#define X first
#define Y second
const int N = 55;
const double PI = acos(-1.0);
double a[N];
double fac[N];
int main() {
srand(time(NULL));
double x = -3;
for(int i = 0; i < 50; ++i) {
double r = (double)(rand() % RAND_MAX) / RAND_MAX;
a[i] = sin(PI * x) / (PI * x) + 0.1 * x + 0.05 * r;
x += 6.0 / 49;
cout<<a[i]<<' ';
}
cout<<endl;
for(int i = 0; i < 50; ++i) {
fac[0] += a[i];
}
fac[0] /= 50;
//cout<<fac[0];
for(int i = 1; i <= 30; ++i) {
x = -3;
double sum = 0;
int f = (i + 1) / 2;
if(i % 2) {
for(int j = 0; j < 50; ++j) {
fac[i] += a[j] * sin(x * f / 2);
sum += sin(x * f / 2);
x += 6.0 / 49;
}
} else {
for(int j = 0; j < 50; ++j) {
fac[i] += a[j] * cos(x * f / 2);
sum += cos(x * f / 2);
x += 6.0 / 49;
}
}
fac[i] /= 50;
//cout<<' '<<fac[i]<<','<<sum<<endl;
}
//cout<<endl;
x = -3;
for(int i = 0; i < 50; ++i) {
double out = fac[0];
for(int j = 1; j <= 30; ++j) {
int f = (j + 1) / 2;
if(j % 2) {
out += fac[j] * sin(x * f / 2);
} else {
out += fac[j] * cos(x * f / 2);
}
}
x += 6.0 / 49;
cout<<out<<' ';
}
cout<<endl;
return 0;
}