链接:

https://codeforces.com/contest/1220/problem/D

题意:

Boy Dima gave Julian a birthday present - set B consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!

Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such way: let all integer numbers be vertices, then connect any two i and j with an edge if |i−j| belongs to B.

Unfortunately, Julian doesn't like the graph, that was built using B. Alex decided to rectify the situation, so he wants to erase some numbers form B, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from B so that graph constructed on the new set is bipartite.

Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.

思路:

如果是二分图, 则不存在奇环,.

考虑存在a,则有0->a, a->2a, 如果存在2a,则有0->2a,就存在奇环,如果有4a, 6a 也会存在奇环, 因为0->4a, 0->6a都属于同一边.

考虑存在p, 有0->p, 同时可以存在, 3p, 5p, 考虑p的最高2的幂在p乘上一个奇数以后不会增加, 所以同时只能存在2的幂与p相等的值.

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10; LL a[MAXN];
int Cnt[MAXN], Num[100];
int n; int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
for (int i = 1;i <= n;i++)
{
LL tmp = a[i];
while (tmp && tmp%2 == 0)
{
Cnt[i]++;
tmp /= 2;
}
Num[Cnt[i]]++;
}
int time = 0, id;
for (int i = 0;i < 64;i++)
if (Num[i] > time)
time = Num[i], id = i;
cout << n-time << endl;
for (int i = 1;i <= n;i++)
{
if (Cnt[i] != id)
cout << a[i] << ' ' ;
}
cout << endl; return 0;
}

Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. virtualbox 扩容存储

    本文讲解一种方式: 第一步: 我们需要将virtual box 设置成全局的环境变量 第二步: 找到要修改的xxx.vdi文件,通过命令来修改 下面操作步骤 1.设置virtual box 的环境变量 ...

  2. kafka 名词解释及原理解析过程(三)

    为什么要了解这些名词的解释呢?因为在学一个新的知识或者领域的时候,我们需要知道它所定义的概念和名词意思,因为只有这样我们才能理解和掌握这个新的知识点,才能更加系统的掌握这个技术. 一.名词解释 1.b ...

  3. 记一次INFA抽取数据报 WRT_8165 - TIMEOUT_BASED_COMMIT_POINT错误

    今天抽取数据报1千多W的数据报错 powercenter workflow卡死不动,也没报错就显示 timeout based commit point  WRT_8165 - TIMEOUT_BAS ...

  4. 报错Could not find resource cn/smbms/dao/provider/ProviderMapper.xml

    原因:由于idea不会编译src下的java目录下的xml文件,所以找不到xml文件 方案一:在pom.xml中添加如下内容 <build> <resources> <r ...

  5. 护卫神等IIS设置Thinkphp框架的public目录为根目录的解决办法

    最近碰到一个棘手的问题,在使用护卫神或者主机宝等IIS环境配置PHP的时候,不能把public设置为网站根目录(因为Thinkphp的安全要求:要将public设置为对外公开目录),这个问题无法搜索到 ...

  6. shell脚本查询某一目录的某一部分文件并且拷贝到其他目录(有则跳过没有则拷贝)

    #!/bin/bash dir=`ls /root//*` for i in $dir do #basename 返回一个字符串参数的基本文件名称.(只剩下文件名除去路径名) a=`basename ...

  7. decimal, double, float

     更新: 2019-09-08  c# and js 要 ceil floor 2 decimal point 都没有 build in 的 solution 比如 15.667 想 ceil to ...

  8. VS 之github

    VS 代码发布到TFS上 1. 登录  visualstudio.com. 进入 https://qgb.visualstudio.com Create Project 这里是相当于新建了一个文件夹 ...

  9. C++string类字符串学习

    1.逆转字符串 第一种,使用algorithm中reverse函数. #include <algorithm> #include <string> #include <i ...

  10. 关于Mybatis的几件小事(二)

    一.MyBatis缓存机制 1.简介 Mybatis包含了一个非常强大的查询缓存的特性,它可以非常方便地配置和定制. 缓存key极大提高查询效率 MyBatis系统中默认定义了两次缓存 默认情况下,只 ...