• Codeforces Round #586 (Div. 1 + Div. 2)


    Codeforces Round #586 (Div. 1 + Div. 2)

    D. Alex and Julian

    Description

    Boy Dima gave Julian a birthday present - set BB 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 ii and jj with an edge if |ij||i−j| belongs to BB.

    Unfortunately, Julian doesn't like the graph, that was built using BB. Alex decided to rectify the situation, so he wants to erase some numbers form BB, 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 BB 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.

    Input

    First line contains an integer n (1n200000)n (1⩽n⩽200000) — size of BB

    Second line contains nn integers b1,b2,,bn (1bi1018)b1,b2,…,bn (1⩽bi⩽1018) — numbers of BB, all bibi are unique

    output

    In first line print single integer kk – number of erased elements. In second line print kk integers – values of erased elements.

    If there are multiple answers, print any of them.

    Examples

    Input

    3
    1 2 3

    Output

    1
    2

    正确解法:

    题目说 如果集合b中有 |i-j| 这个数时,就把 i 和 j 连一条边。

    图有无数个点无数个边,求删除尽量少的数使图是一个二分图。

    通过画图,发现 当有 2 8 的时候,2和8肯定不能在一起。

    这就引入了一个2的k次幂的问题。

    当两个数同时除 2^k 时变成了两个奇数。 这就可以了。

    二分图必须是偶环。

    但是这么多组合怎么知道删除哪个最优呢?

    我看到了这个:

     1 for(int i=1;i<=n;i++)
     2     {
     3         scanf("%lld",&num[i]);
     4         int k=0;
     5         x=num[i];
     6         while(x%2==0)
     7         {
     8             x/=2;
     9             k++;
    10         }
    11         a[k].push_back(i);
    12     }

    于是找到最大的那个集合就可以了。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string>
     4 #include<algorithm>
     5 #include<vector>
     6 #include<cstring>
     7 #include<numeric>
     8 #include <cmath>
     9 #include<map>
    10 using namespace std;
    11 typedef long long ll;
    12 const int SIZE = 1010;
    13 const int mod=1e9+7;
    14 const int N=2e5+100;
    15 int n,m;
    16 ll num[N],x;
    17 vector<ll>a[70];
    18 int main()
    19 {
    20     scanf("%d",&n);
    21     for(int i=1;i<=n;i++)
    22     {
    23         scanf("%lld",&num[i]);
    24         int k=0;
    25         x=num[i];
    26         while(x%2==0)
    27         {
    28             x/=2;
    29             k++;
    30         }
    31         a[k].push_back(i);
    32     }
    33     m=-1;
    34     for(int i=0;i<=64;i++)
    35     {
    36         if(m==-1||a[m].size()<a[i].size())
    37             m=i;
    38     }
    39     printf("%d
    ",n-a[m].size());
    40     for(int i=0;i<=64;i++)
    41     {
    42         if(i==m)    continue;
    43         for(int j=0;j<a[i].size();j++)
    44             printf("%lld ",num[a[i][j]]);
    45     }
    46 
    47 
    48 
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    关于ShareSDK接入的各种问题,以及解决方案
    Cocos2d-x使用iOS游戏内付费IAP(C++篇)
    数论——终结素数判定
    poj 2528 线段树+离散化
    STL 优先队列
    poj 2777 线段树+延迟更新
    RMQ
    codeforces 拼手速题2
    codeforces 拼手速题1
    子矩阵 思维吧
  • 原文地址:https://www.cnblogs.com/Kaike/p/11552279.html
Copyright © 2020-2023  润新知