CodeForces 1287B Hyperset

 

 

N^2遍历所有得(i,j)然后可以根据(i,j)字符串构造出来第三个T字符串,然后查找一下是否有这个T存在即可,注意最后答案要/3因为会重复出现。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <sstream>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const int mod=1e9+7;
16 const double PI = acos(-1);
17 #define Bug cout<<"---------------------"<<endl
18 const int maxn=1e4+10;
19 using namespace std;
20 
21 
22 int main()
23 {
24     #ifdef DEBUG
25     freopen("sample.txt","r",stdin);
26     #endif
27     ios_base::sync_with_stdio(false);
28     cin.tie(NULL);
29     
30     int n,m;
31     cin>>n>>m;
32     int ans=0;
33     string str[1505];
34     set<string> st;
35     for(int i=0;i<n;i++)
36     {
37         cin>>str[i];
38         st.insert(str[i]); 
39     }     
40     for(int i=0;i<n;i++)
41     {
42         for(int j=i+1;j<n;j++)
43         {
44             string s="";
45             for(int k=0;k<m;k++)
46             {
47                 
48                 if(str[i][k]!=str[j][k])
49                 {
50                     int t[3]={0};
51                     if(str[i][k]=='S'||str[j][k]=='S') t[0]=1;
52                     if(str[i][k]=='E'||str[j][k]=='E') t[1]=1;
53                     if(str[i][k]=='T'||str[j][k]=='T') t[2]=1;
54                     for(int p=0;p<3;p++)
55                     {
56                         if(!t[p])
57                         {
58                             if(p==0) s+='S';
59                             else if(p==1) s+='E';
60                             else s+='T';
61                         }
62                     }
63                 }
64                 else
65                     s+=str[i][k];
66             }
67             if(st.count(s)) ans++;
68         }
69     }
70     cout<<ans/3<<endl;
71     
72     
73     
74     return 0;
75 }
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define pb push_back
#define all(v) (v.begin(),v.end())
#define mp make_pair

string e[1505];
int n,K;
map<string,int>M;

int main()
{
    ios::sync_with_stdio(false);
    int S='S'+'E'+'T';
    long long ans=0;
    cin>>n>>K;
    for(int i=1;i<=n;++i)cin>>e[i],M[e[i]]++;
    for(int i=1;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            if(i==j)continue;
            string T;
            for(int o=0;o<K;++o){
                if(e[i][o]==e[j][o]) T+=e[i][o];
                else{
                        T+=(char)(S-e[i][o]-e[j][o]);
                }
            }
            ans+=M[T];
        }
    }cout<<ans/3<<endl;
    return 0;
}

-

原文地址:https://www.cnblogs.com/jiamian/p/12166051.html