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;
    }
    
  • 相关阅读:
    JQuery中的动画
    javascript之变量、作用域、作用域链
    正确理解javascript的this关键字
    我忽略了的DOCTYPE!
    JQuery中的DOM操作
    发布一款html5移动端scroll框架:xScroll
    在debug时使Flutter中的print打印json数据时更美观易读
    使用ValueListenableBuilder监听TextEditingController
    Flutter使用rxdart和ChangeNotifier实现的倒计时按钮
    Flutter设计一个长按自动步进的按钮
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11626998.html
Copyright © 2011-2022 走看看