二进制转十进制 然后按位比较
传送门 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); } }