zoukankan      html  css  js  c++  java
  • codeforces Gym 101063 C

    二进制转十进制 然后按位比较 

    传送门 http://codeforces.com/gym/101063

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <sstream>
    #include <algorithm>
    #include <string>
    #include <queue>
    #include <vector>
    using namespace std;
    const int maxn= 100005;
    const double eps= 1e-6;
    const int inf = 0x3f3f3f3f;
    const int mod =3;
    typedef long long ll;
    typedef long double ld;
    int n,m;
    int a[maxn][15];
    int b[maxn];
    ll c[maxn];
    ll d[maxn];
    int main()
    {
        while(scanf("%d %d",&n,&m)!=EOF)
        {
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            for(int i=1;i<=n;i++)
            {
                int t;
                scanf("%d",&t);
                for(int j=1;j<=t;j++)
                {
                    scanf("%d",&a[i][j]);
                    b[i]+=(1<<(a[i][j]-1));
                }
                c[b[i]]++;
            }
            for(int i=1;i<=1023;i++)
            {
                int k=i;
                d[i]=0;
                while(k>0)
                {
                    if(k%2)
                        d[i]++;        //i转换成二进制有多少个1
                    k/=2;
                }
                //printf("%d %d
    ",i,d[i]);
            }
            ll ans=0;
            ld r;
            cin>>r;
            for(int i=1;i<=1023;i++)
            {
                for(int j=i;j<=1023;j++)
                {
                    int q=i&j,p=i|j;
                    ld k=(ld)d[q]/(ld)d[p];
                    if(k>=r)
                    {
                        if(i!=j)
                            ans+=c[i]*c[j];
                        else
                            ans+=c[i]*(c[i]-1)/2;
                    }
                }
            }
            printf("%I64d
    ",ans);
        }
    }
  • 相关阅读:
    2015 省赛随便写写
    有向图强连通分量
    复杂状态的动态规划
    hdu 3350
    树状DP
    十字链表矩阵
    最优矩阵链乘
    poj 3778
    Poj 3771 hdu 3405
    [2015hdu多校联赛补题]hdu5302 Connect the Graph
  • 原文地址:https://www.cnblogs.com/stranger-/p/7896464.html
Copyright © 2011-2022 走看看