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;
    }
    
  • 相关阅读:
    laravel windows下安装 gulp 和 laravel-elixir
    php-新特性,生成器的创建和使用
    laravel 使用极验验证码
    laravel 发送邮件
    laravel安装 redis 并驱动 session
    理解HTTP协议(转载)
    iOS中Block的用法,举例,解析与底层原理
    iOS自定义结构体
    dyld环境变量
    iOS中的静态库与动态库,区别、制作和使用
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11626998.html
Copyright © 2011-2022 走看看