Codeforces 1220D - Alex and Julian 题解

妈个唧看错题了

题解 #

详细题解可以看英文版。简单写一下要点吧,这题关键在于理解环是怎么形成的,环的长度是多少,以及为什么当且仅当两个数包含相同 2 的幂的时候环的长度是偶数。

Code #

#include <bits/stdc++.h>
 
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename... Args>
void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
    cin>>n;
    vector<ll> cnt[60];
    forn(i,n){
        ll x;
        cin>>x;
        ll tmp=x;
        int c=0;
        while(x%2==0) x/=2,c++;
        cnt[c].pb(tmp);
    }
    int mx=0,idx;
    forn(i,60) if(size(cnt[i])>mx){
        mx=size(cnt[i]);
        idx=i;
    }
    cout<<n-size(cnt[idx])<<endl;
    forn(i,60){
        if(i!=idx){
            for(auto it:cnt[i]) cout<<it<<' ';
        }
    }
 
    return 0;
}

参考资料 #

https://codeforces.com/blog/entry/69901

https://codeforces.com/blog/entry/69899