Hyperset

题意:有一系列卡片,要求从他们中选出三张卡片构成一个集合,三张卡片构成集合的要求是:对应位置字母要么三张都相同,要么三张都不同。问有多少种选择方案。

思路:当确定前两个字符串时,第三个字符串也确定了,可以枚举算出第三个字符串,再用map查找

 1 #include<iostream>
 2 #include<string.h>
 3 #include<cmath>
 4 #include<map>
 5 using namespace std;
 6 typedef long long ll;
 7 const int INF=0x3f3f3f3f;
 8 int n,k;
 9 int ans=0;
10 string s[1505];
11 int main() {
12     ios::sync_with_stdio(false);
13     cin>>n>>k;
14     map<string,int> mp;
15     for(int i=0;i<n;++i){
16         cin>>s[i];
17         mp[s[i]]=i;
18     }
19     string c;
20     for(int i=0;i<n;++i){
21         for(int j=i+1;j<n;++j){
22             string a=s[i];
23             string b=s[j];
24             c="";
25             for(int t=0;t<k;++t){
26                 if(a[t]==b[t]){
27                     c+=a[t];
28                 }
29                 else if((a[t]=='T'&&b[t]=='E')||(a[t]=='E'&&b[t]=='T')) {
30                     c+='S';
31                 }
32                 else if((a[t]=='T'&&b[t]=='S')||(a[t]=='S'&&b[t]=='T')){
33                     c+='E';
34                 }
35                 else if((a[t]=='S'&&b[t]=='E')||(a[t]=='E'&&b[t]=='S')){
36                     c+='T';
37                 }
38             }
39             //mp[c]>j 确保顺序 
40             if(mp.count(c)&&mp[c]>j){
41                 ans++;
42             }
43         }
44     }
45     cout<<ans<<endl;
46     return 0;
47 }

 

posted @ 2020-08-08 23:04  吉吉的奥利奥  阅读(438)  评论(0编辑  收藏  举报