Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维

传送门

文章目录

题意:

给你一个无限个点的坐标轴,一个集合 B B B,如果存在 ∣ i − j ∣ = b k |i-j|=b_k ij=bk的话,那么 i , j i,j i,j之间就连边。现在问你至少要从集合 B B B中去掉多少个数才能使得连完边之后这个图是二分图。
n ≤ 2 e 5 , B i ≤ 1 e 18 n\le2e5,B_i\le1e18 n2e5,Bi1e18

思路:

首先一个图是二分图的条件是不存在奇环,那么假设集合中有两个数 x , y x,y x,y,如果存在两个正整数 a , b a,b a,b使得 a x = b y ax=by ax=by ( a + b )   m o d   2 = 0 (a+b)\bmod2=0 (a+b)mod2=0的话,那么这两个数是可以同时存在的。
转换一下就是 ( l c m ( x , y ) x + l c m ( x , y ) y )   m o d   2 = 0 (\frac{lcm(x,y)}{x}+\frac{lcm(x,y)}{y})\bmod 2=0 (xlcm(x,y)+ylcm(x,y))mod2=0的时候才可以,即 x + y g c d ( x , y )   m o d   2 = 0 \frac{x+y}{gcd(x,y)}\bmod2=0 gcd(x,y)x+ymod2=0
现在分情况讨论一下:
( 1 ) x , y (1)x,y (1)x,y都为奇数,由于只有 奇数 ∗ * 奇数 = = =奇数, x + y g c d ( x , y )   m o d   2 = 0 \frac{x+y}{gcd(x,y)}\bmod2=0 gcd(x,y)x+ymod2=0显然成立。
( 2 ) x , y (2)x,y (2)x,y一个奇数一个偶数,这里跟上面同理由于 g c d ( x , y ) gcd(x,y) gcd(x,y)一定为奇数,多了一个 偶数 ∗ * 奇数=偶数, x + y g c d ( x , y )   m o d   2 = 1 \frac{x+y}{gcd(x,y)}\bmod2=1 gcd(x,y)x+ymod2=1显然不可以。
( 3 ) x , y (3)x,y (3)x,y都为偶数,这个时候可以将两个数共同除 2 2 2消去末尾 0 0 0,之后转换成上面两种情况。

通过上面的规律可以发现,我们按照末尾 0 0 0的个数来分组即可。

// Problem: D. Alex and Julian
// Contest: Codeforces - Codeforces Round #586 (Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/1220/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n;
LL a[N];
vector<LL>v[100];

int get(LL x) {
	int id;
	for(int i=60;i>=0;i--) if(x>>i&1) id=i;
	return id;
}

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);
		
	cin>>n;
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		v[get(a[i])].pb(a[i]);
	}
	int id,mx=0;
	for(int i=0;i<=60;i++) if(v[i].size()>mx) mx=v[i].size(),id=i;
	printf("%d\n",n-mx);
	for(int i=0;i<=60;i++) {
		if(id==i) continue;
		for(auto x:v[i]) printf("%lld ",x);
	}

	
	
	



	return 0;
}
/*
*/









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值