-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lissage de Signal.cpp
45 lines (39 loc) · 1023 Bytes
/
Lissage de Signal.cpp
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
#include <bits/stdc++.h>
#define for_n(i, a, n) for (ll i = a; i < n; i++)
#define ll long long
#define v(t) vector<t>
using namespace std;
double diffMax;
ll nb;
void print(v(double) &v){
for_n(i, 0, v.size()){
cout << v[i] << " ";
}
cout << endl;
}
bool Check(v(double) mesures){
for_n(i, 0, mesures.size() - 1){
if(abs(mesures[i] - mesures[i + 1]) > diffMax){
return false;
}
}
return true;
}
ll Lissage(v(double) mesures){
v(double) new_mesures;
new_mesures.push_back(mesures[0]);
for_n(i, 1, mesures.size() - 1){
new_mesures.push_back((mesures[i - 1] + mesures[i + 1]) / 2);
}
new_mesures.push_back(mesures[mesures.size() - 1]);
nb++;
if (!Check(new_mesures)) Lissage(new_mesures);
return nb;
}
int main(){
ll nbMesures;
cin >> nbMesures >> diffMax;
v(double) mesures(nbMesures);
for(auto &t : mesures) cin >> t;
cout << Lissage(mesures) << endl;
}