zoukankan      html  css  js  c++  java
  • LibreOJ #526. 「LibreOJ β Round #4」子集

    二次联通门 : LibreOJ #526. 「LibreOJ β Round #4」子集

    /*
        LibreOJ #526. 「LibreOJ β Round #4」子集
    
        考虑一下,若两个数奇偶性相同
        若同为奇数, 那加1后就是偶数, gcd的乘积就一定不是1
        偶数相同
    
        那么我们把原数中的偶数分为一个集合,奇数分为一个集合
        把互相之间不符合要求的连边
    
        那么问题就转化为了二分图求最大独立集
    */
    #include <cstdio>
    #include <iostream>
    #include <queue>
    #include <cstring>
    
    const int BUF = 12312312;
    char Buf[BUF], *buf = Buf;
    #define INF 1e9
    inline void read (long long &now)
    {
        for (now = 0; !isdigit (*buf); ++ buf);
        for (; isdigit (*buf); now = now * 10 + *buf - '0', ++ buf);
    }
    
    #define Max 600
    struct E { E *n, *r; int v, f; };
    E *list[Max], poor[Max * 10000], *Ta = poor;
    int S, T;
    
    class Flow_Type
    {
        private :
    
            int d[Max];
    
            bool Bfs (int S, int T)
            {
                memset (d, -1, sizeof d); d[S] = 0;
                std :: queue <int> Queue; int now; E *e;
                for (Queue.push (S); !Queue.empty (); Queue.pop ())
                {
                    now = Queue.front ();
                    for (e = list[now]; e; e = e->n)
                        if (d[e->v] == -1 && e->f)
                        {
                            d[e->v] = d[now] + 1;
                            if (e->v == T) return true;
                            Queue.push (e->v);
                        }
                }
                return d[T] != -1;
            }
            
            int Flowing (int now, int F)
            {
                if (now == T || !F) return F;
                int res = 0, pos; E *e;
                for (e = list[now]; e; e = e->n)
                {
                    if (d[e->v] != d[now] + 1 || !e->f) continue;
                    pos = Flowing (e->v, e->f < F ? e->f : F);
                    if (pos)
                    {
                        F -= pos, res += pos, e->f -= pos, e->r->f += pos;
                        if (!F) return res;
                    }
                }
                if (res != F) d[now] = -1;
                return res;
            }
    
        public :
    
            inline void In (int u, int v)
            {
                ++ Ta, Ta->v = v, Ta->n = list[u], list[u] = Ta, Ta->f = 1;
                ++ Ta, Ta->v = u, Ta->n = list[v], list[v] = Ta, Ta->f = 0;
                list[u]->r = list[v], list[v]->r = list[u];
            }
            
            int Dinic (int S, int T)
            {
                int Answer = 0;
                for (; Bfs (S, T); Answer += Flowing (S, INF));
                return Answer;
            }
    };
    
    Flow_Type F;
    long long key[Max];
    long long Gcd (long long a, long long b) { return !b ? a : Gcd (b, a % b); }
    int Main ()
    {
        fread (buf, 1, BUF, stdin);
        long long N; read (N); S = N + 1, T = N + 2;
        register int i, j;
        for (i = 1; i <= N; ++ i)
        {
            read (key[i]);
            if (key[i] & 1) F.In (i, T);
            else F.In (S, i);
        }
        for (i = 1; i <= N; ++ i)
        {
            if ((key[i] & 1) == 0)
                for (j = 1; j <= N; ++ j)
                    if (key[j] & 1)
                        if (Gcd (key[i], key[j]) == 1 && Gcd (key[i] + 1, key[j] + 1) == 1)
                            F.In (i, j);
        }
    
        printf ("%d", N - F.Dinic (S, T));
    
        return 0;
    }
    
    int ZlycerQan = Main ();
    int main (int argc, char *argv[]) {;}
  • 相关阅读:
    Python深拷贝和浅拷贝解析
    python中count函数的用法
    Jenkins + gitlab + maven 自动打包部署项目
    nio和bio得区别
    nginx负载均衡的5种策略
    接口测试常见bug
    接口自动化面试4
    pass 语句
    if 语句
    while循环
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/7469196.html
Copyright © 2011-2022 走看看