Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.     int n;
  11.     cin >> n;
  12.     vector <int> a(n);
  13.     for(int i = 0;i<n;++i){
  14.         cin >> a[i];
  15.     }
  16.     int cur = 0;
  17.     int ans = 1;
  18.     int k;
  19.     for(int i = 1;i<n;++i){
  20.         if(i==1){
  21.             k = a[i]-a[i-1];
  22.             if(k%2!=0 || k==0){
  23.                 k = a[i+1]-a[i];
  24.                 ans++;
  25.             }
  26.         }
  27.         else{
  28.             if((a[i]-a[i-1])%2!=0){
  29.                 ans++;
  30.                 if(i==n-1)
  31.                     break;
  32.                 k = a[i+1]-a[i];
  33.             }
  34.             else{
  35.                 int kl = a[i]-a[i-1];
  36.                 if(kl!=k || k==0){
  37.                     ans++;
  38.                     if(i==n-1)
  39.                         break;
  40.                     k = a[i+1]-a[i];
  41.                 }
  42.             }
  43.         }
  44.     }
  45.     cout << ans;
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement