greedy math

Please click on ads to support us..

C++ Code:

//       __
//    __/__\_
//     O | |
//    / \| |
//   /  /| |
//     / | |

//author: PS_455
    
//header files
#include <bits/stdc++.h>
using namespace std;

    
//define shortcuts
#define ll long long
#define endl "\n"
#define int ll
#define ld long double
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define vll vector<ll>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define scanit(a,n) for(ll index1=0; index1<n; index1++) cin>>a[index1];
#define printit(a,n) for(ll index1=0; index1<n; index1++) cout<<a[index1]<<" ";
#define precision(a) cout<<fixed<<setprecision(a)
#define FASTO ios_base::sync_with_stdio(false); cin.tie(NULL);
    
//functions
int __gcd(int a, int b) { if(b == 0){return a;} return __gcd(b, a % b); }
ll binpow(ll a, ll b) { ll res = 1; while (b > 0){ if(b & 1){res = (res * a);} a = (a * a) ; b >>= 1; } return res; }
bool isPrime(ll n){ if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; ll p = sqrt(n); for(int i=5; i<=p; i=i+6){ if(n%i==0 || n%(i+2)==0) return false;} return true;}    
void remove(vector<int> &v){auto end = v.end();for(auto it = v.begin(); it != end; ++it){end = std::remove(it + 1, end, *it);} v.erase(end, v.end()); }

const ll M = 1000000007;

/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/

void solve(){
     int n;
     cin>>n;
     int ans=0;
     vector<int> v(n);
     scanit(v,n);
     for(int i=0; i<n-1; i++){
        if(v[i]%2==v[i+1]%2) ans+=1;
     }
     cout<<ans<<endl;
}
    
int32_t main(){
    
    FASTO

    int t=1;
    cin>>t;
    
    while(t--){
    solve();
    }
    
    return 0;
}


Comments

Submit
0 Comments
More Questions

254A - Cards with Numbers
215A - Bicycle Chain
1288B - Yet Another Meme Problem
1201C - Maximum Median
435A - Queue on Bus Stop
1409B - Minimum Product
723B - Text Document Analysis
1471C - Strange Birthday Party
1199A - City Day
1334A - Level Statistics
67B - Restoration of the Permutation
1734A - Select Three Sticks
1734B - Bright Nice Brilliant
357B - Flag Day
937A - Olympiad
1075A - The King's Race
1734C - Removing Smallest Multiples
1004C - Sonya and Robots
922A - Cloning Toys
817A - Treasure Hunt
1136B - Nastya Is Playing Computer Games
1388A - Captain Flint and Crew Recruitment
592B - The Monster and the Squirrel
1081A - Definite Game
721C - Journey
1400A - String Similarity
1734E - Rectangular Congruence
1312D - Count the Arrays
424C - Magic Formulas
1730C - Minimum Notation