FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-Ninjas-Competitive-Programming/FFT/FFT_Code.cpp at master · CodeB3nder/Coding-Ninjas-Competitive-Programming · GitHub
CodeB3nder
/
Coding-Ninjas-Competitive-Programming
Public
forked from
parikshit223933/Coding-Ninjas-Competitive-Programming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-Ninjas-Competitive-Programming
/
FFT
/
FFT_Code.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (63 loc) · 1.36 KB
Breadcrumbs
Coding-Ninjas-Competitive-Programming
/
FFT
/
FFT_Code.cpp
Copy path
File metadata and controls
64 lines (63 loc) · 1.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
vector
>
#
include
<
complex
>
#
include
<
math.h
>
#
include
<
iostream
>
#
define
endl
'
\n
'
#
define
int
long
long
#
define
fast
\
ios_base::sync_with_stdio
(
false
); \
cin.tie(
0
)
#
define
base
complex
<
double
>
using
namespace
std
;
vector<base>
init_omega
(
int
n)
{
vector<base>
omega
(n);
double
PI
=
acos
(-
1
);
double
angle =
2
* (
PI
/ n);
for
(
int
i =
0
; i < n; i++)
{
omega[i] =
base
(
cos
(angle * i),
sin
(angle * i));
}
return
omega;
}
vector<base>
fft
(vector<base> &a, vector<base> omega)
{
int
n = (
int
)a.
size
();
if
(n ==
1
)
{
return
a;
}
int
half = n >>
1
;
//
it is n/2
vector<base>
aeven
(half);
vector<base>
aodd
(half);
for
(
int
i =
0
, j =
0
; i < n; i +=
2
, j++)
{
aeven[j] = a[i];
aodd[j] = a[i +
1
];
}
auto
yeven =
fft
(aeven, omega);
auto
yodd =
fft
(aodd, omega);
vector<base>
y
(n);
for
(
int
i =
0
; i < half; i++)
{
y[i] = yeven[i] + omega[i] * yodd[i];
y[i + half] = yeven[i] - omega[i] * yodd[i];
}
return
y;
}
int32_t
main
()
{
fast;
vector<base> a;
a.
push_back
(
1
);
a.
push_back
(
2
);
a.
push_back
(
3
);
a.
push_back
(
4
);
vector<base> omega =
init_omega
(a.
size
());
vector<base> y =
fft
(a, omega);
for
(
int
i =
0
; i < y.
size
(); i++)
{
cout << y[i] << endl;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL