Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian(二分图判断+数学)

题目链接
在这里插入图片描述
思路:虽然知道判断二分图是判断存不存在奇环,但这题还存在着一些细节未懂,先留坑。。。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+1;
ll a[maxn],num[maxn],cnt[maxn];
int main()
{
	int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
    {
        ll temp=a[i];
        while(temp&&temp%2==0)
        {
            cnt[i]++;
            temp/=2;
        }
        num[cnt[i]]++;
    }
    int id=0;
    for(int i=1;i<=63;i++) if(num[i]>num[id]) id=i;
    printf("%d\n",n-num[id]);
    for(int i=1;i<=n;i++) if(cnt[i]!=id) printf("%lld ",a[i]);
    return 0;
}
发布了144 篇原创文章 · 获赞 0 · 访问量 4961

猜你喜欢

转载自blog.csdn.net/qq_42479630/article/details/104434780