Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian
链接:
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的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
随机推荐
- Pycharm 误删文件夹
在Linux下操作时误删除了Pycharm项目中的文件夹,打开垃圾桶,居然找不到,立马上网查Linux下怎么恢复文件, 冷静一下,不是还有个Ctrl + Z吗,对着Pycharm 文件浏览器 按一下, ...
- Kafka 原理
消息队列内部实现原理 两种消息传输方式 Kafka kafka 简介 kafka 集群角色 Kafka 工作流程分析 Kafka 生产过程分析 写入方式 分区(partition) 副本(replic ...
- DB2创建EMP和DEPT并进行基础操作
一.DB2创建EMP和DEPT测试表 --DB2创建测试表 CREATE TABLE TEST.EMP (EMPNO INTEGER NOT NULL, ENAME ), JOB ), MGR INT ...
- Linux基础指令--文件操作
mkdir a 创建一个名为a的文件夹 touch a.txt 创建一个名为a.txt的文件 mv b sm/ 将文件(夹)b 移动到当前目录下的sm目录下 rm -rf a 删除 a文件 -rf为参 ...
- Ubuntu 安装 QtCreator (version : Qt 5.9.8)
平台 :Ubuntu 16.04 QT :5.9.8 (open source) 首先去QT安装包下载安装包,为了保持与arm板子的统一,本人选择了 5.9.8 版本的QT 可 ...
- Mysql数据库的优化(本文摘自于网络,文章末端有原文链接)
对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要.一 般来说,要保证数据库的效率,要做好以下四个方面的工作: ① 数据库设计 ② sql语句优化 ③ 数据库参数配置 ...
- 关于DB2的使用(DB2数据命令)
公司所用的数据库有金仓和DB2 首先要用命令窗口直接打开db2需要在cmd中输入:db2cmd 1:启动DB2数据库:db2start 2:连接数据库:db2 connect to 数 ...
- Nginx安装启动过程报错libpcre.so.1 cannot open shared object file: No such file or directory
具体报错信息如下: nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: ...
- javascript——获取元素方式
//1:依据id //var element = document.getElementById("test"); console.log(element); //2:依据clas ...
- SIP协议入门:初学者必须明白的几个重要概念
SIP协议初学者必须明白的几个重要概念 http://blog.sina.com.cn/s/blog_60e1d7bb0100f6er.html 一. SIP协议的分层结构 SIP是一个分层结构协议, ...