P5123 [USACO18DEC]Cowpatibility(容斥)
发布时间:2020-12-14 04:38:48 所属栏目:大数据 来源:网络整理
导读:Luogu5123 计算[两组数中有相同的]= (sum_{i}) 两组数中 (i) 个数相同的组合方案 map string,int 操作 (:) 加上 (,) 防止算重 #includecstdio#includeiostream#includealgorithm#includetr1/unordered_map#define debug(...) fprintf(stderr,__VA_A
Luogu5123 计算[两组数中有相同的]=(sum_{i})两组数中(i)个数相同的组合方案 map <string,int> 操作(:)加上(,)防止算重 #include<cstdio> #include<iostream> #include<algorithm> #include<tr1/unordered_map> #define debug(...) fprintf(stderr,__VA_ARGS__) #define Debug(x) cout<<#x<<"="<<x<<endl using namespace std; typedef long long LL; const int INF=1e9+7; inline LL read(){ register LL x=0,f=1;register char c=getchar(); while(c<48||c>57){if(c=='-')f=-1;c=getchar();} while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar(); return f*x; } tr1::unordered_map <string,LL> F; string a[7]; LL n,ans,Ans; int main(){ n=read(); Ans=n*(n-1)/2; while(n--){ for(int i=1;i<=5;i++) cin>>a[i]; sort(a+1,a+6);//一般都要排序 ans=0; for(int i=1;i<32;i++){ int cnt=0;string s=""; for(int j=1;j<=5;j++){ if(i&(1<<(j-1))) cnt++,s+=a[j]+",";//用,隔开防止算重 } if(cnt&1) ans+=F[s]++; else ans-=F[s]++; } Ans-=ans;//减去和谐的就是不和谐的 } printf("%lldn",Ans); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |