zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    UVA 10608 Friends
    UVA 10806 Dijkstra, Dijkstra.
    HDU 3715 Go Deeper
    poj1315
    poj1383
    poj1650
    poj1265
    poj1523
    RedHat9.0虚拟机安装
    注册DirectShow filter时应该注意中文路径
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11626998.html