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

    一道脑洞题,我们发现不能在一起的点对还是比较少的。

    我们考虑奇偶性,发现同奇偶性时一定可以,那么我们统计不可以的对,答案就是n-二分图的最大匹配。

    #include<bits/stdc++.h>
    #define N 507
    #define int long long
    using namespace std;
    int x,a[N],b[N],usd[N],c[N],d[N][N],n,ta,tb,tot;
    int gcd(int x,int y){
        return y?gcd(y,x%y):x;
    }
    bool check(int x,int y){
        return gcd(x,y)==1&&gcd(x+1,y+1)==1;
    }
    bool find(int x){
        if (!x) return 1;
        for (int i=1;i<=tb;i++)  
        if (!usd[i]&&d[x][i])
             { usd[i]=1; 
               if (find(c[i])){
                   c[i]=x;
                 return 1; }
                 }        
             return 0;
    }
    signed main () {
    //    freopen("aaa.in","r",stdin);
        scanf("%lld",&n);
        for (int i=1;i<=n;i++) {
         scanf("%lld",&x);x&1?a[++ta]=x:b[++tb]=x;}
        for (int i=1;i<=ta;i++)
         for (int j=1;j<=tb;j++) d[i][j]=check(a[i],b[j]);
        for (int i=1;i<=ta;i++) {
           memset(usd,0,sizeof usd);
           if (find(i)) tot++;
        }
        printf("%lld",n-tot);
    }
  • 相关阅读:
    Html5结构相关元素
    html5文本元素
    html5全局属性
    元数据元素总结
    千里之行,始于足下
    换个角度思考
    java的权限修饰符
    四则运算
    测量软件使用感受
    JQuery高级
  • 原文地址:https://www.cnblogs.com/rrsb/p/8337948.html
Copyright © 2011-2022 走看看