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
| #include<iostream>
#include<string>
#include <cmath>
using namespace std;
double valabs(double);
double valabs(double a)
{
if (a<0)
return (-1*a);
else
return a;
}
int main()
{
int nbMesures;
double diffMax;
int a=0;
int nb=-1;
double *tab;
double *tab2;
bool b=true;
int k=2;
cin>>nbMesures;
cin>>diffMax;
tab=new double[nbMesures];
tab2=new double [nbMesures];
for(int i=0;i<nbMesures;i++)
{
cin>>tab[i];
}
tab2[0]=tab[0];
tab2[nbMesures-1]=tab[nbMesures-1];
while(b)
{
b=false;
nb=nb+1;
if(a==0)
{
for(int i=1;i<nbMesures-1;i++)
{
tab2[i]= (tab[i-1]+tab[i+1])/2.0;
}
}
if(a==1)
{
for(int i=1;i<nbMesures-1;i++)
{
tab[i]= (tab2[i-1]+tab2[i+1])/2.0;
}
}
for(int j=0;j<nbMesures-1 && !b;j++)
{
b=((valabs(tab[j]-tab[j+1])>diffMax) || (valabs(tab2[j]-tab2[j+1])>diffMax));
}
k=k+1;
a=k%2;
}
cout<<nb;
delete tab;
delete tab2;
system("pause");
return 0;
} |
Partager