codeforces Gym 101063 C
阿新 • • 發佈:2017-11-25
blank ostream con ans pac sin %d sca mes
二進制轉十進制 然後按位比較
傳送門 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> usingnamespace 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\n",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\n",ans); } }
codeforces Gym 101063 C