#include<iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; int wyn=0; int wyn2=0; int tab[n]; int pom[n]; for(int i=0;i<n;++i){ cin>>pom[i]; tab[i]=pom[i]; } int ocz=0; // 0 to mniejsza 1 to wieksza for(int i=1;i<n;++i){ if(ocz==0 && tab[i-1]<=tab[i] || ocz==1 && tab[i-1]>=tab[i] ){ ++wyn; if(ocz==0){ tab[i]=tab[i+1]-1; } else{ tab[i]=tab[i+1]+1; } } if(ocz==0)ocz=1; else ocz=0; } ocz=1; for(int i=0;i<n;++i){ tab[i]=pom[i]; } // 0 to mniejsza 1 to wieksza for(int i=1;i<n;++i){ if(ocz==0 && tab[i-1]<=tab[i] || ocz==1 && tab[i-1]>=tab[i] ){ ++wyn2; if(ocz==0){ tab[i]=tab[i+1]-1; } else{ tab[i]=tab[i+1]+1; } } if(ocz==0)ocz=1; else ocz=0; } if(wyn>wyn2)cout<<wyn2; else cout<<wyn; return 0; }
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 | #include<iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; int wyn=0; int wyn2=0; int tab[n]; int pom[n]; for(int i=0;i<n;++i){ cin>>pom[i]; tab[i]=pom[i]; } int ocz=0; // 0 to mniejsza 1 to wieksza for(int i=1;i<n;++i){ if(ocz==0 && tab[i-1]<=tab[i] || ocz==1 && tab[i-1]>=tab[i] ){ ++wyn; if(ocz==0){ tab[i]=tab[i+1]-1; } else{ tab[i]=tab[i+1]+1; } } if(ocz==0)ocz=1; else ocz=0; } ocz=1; for(int i=0;i<n;++i){ tab[i]=pom[i]; } // 0 to mniejsza 1 to wieksza for(int i=1;i<n;++i){ if(ocz==0 && tab[i-1]<=tab[i] || ocz==1 && tab[i-1]>=tab[i] ){ ++wyn2; if(ocz==0){ tab[i]=tab[i+1]-1; } else{ tab[i]=tab[i+1]+1; } } if(ocz==0)ocz=1; else ocz=0; } if(wyn>wyn2)cout<<wyn2; else cout<<wyn; return 0; } |