Codeforces Round #612 (Div. 2) B. Hyperset

题目:https://codeforces.com/contest/1287/problem/B
思路:先找一对 \(cards\)
若其某特征值相同,那第三个 \(cards\) 该特征值也相同
若不同,第三个 \(cards\) 该特征值也不同
这样就能确定第三个 \(cards\) 找出其个数即可
最后答案\(\div 3\)
时间复杂度:\(O(kn^2logn)\)

#include<bits/stdc++.h>
 
using namespace std;
 
const int N=1505;
const int SET='S'+'E'+'T';
 
int n,k;
string s[N];
map<string,int>m;
int ans;
 
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>s[i],m[s[i]]++;    
        for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            string t="";
            for(int p=0;p<k;p++)
            {
                if(s[i][p]==s[j][p]) t+=s[i][p];
                else t+=SET-s[i][p]-s[j][p];
            }
            if(m.count(t)) ans+=m[t];
        }
    cout<<ans/3<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/c4Lnn/p/12163094.html