Codeforces Round #612 (Div. 2) B. Hyperset(枚举+map)

题目地址:https://codeforces.com/contest/1287/problem/B
n行字符串,每个字符串k个字符,每个字符串只能是’S’、‘T’、'E’这三个字符,三个字符串算一组,问有多少组。

3 3
SET
ETS
TSE
//第一列SET都不一样,第二列ETS都不一样,第三列TSE都不一样
//所以这三个字符串算1组
3 4
SETE
ETSE
TSES
//第一列SET都不一样,第二列ETS都不一样,第三列TSE都不一样,第四列EES
//有两个一样的,所以这三个字符串不算一组

解决方法:输入时map存储,暴力枚举前两个,找出那个唯一的第三个字符,map查询该字符是否存在,存在则加上

AC代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#define ll long long
#define dd double
#define PI acos(-1.0)
#define f(i, x, y) for(ll i = x; i < y; i++)
using namespace std;
const ll MAXN = 2e5 + 5;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k; cin >> n >> k;
	string s[1505];
	map<string, ll> ma;
	f(i, 0, n) {
		cin >> s[i];
		ma[s[i]]++;
	}
	ll cnt = 0;
	f(i, 0, n - 1) {
		f(j, i + 1, n) {
			string ss = "";
			f(x, 0, k) {
				if (s[i][x] == s[j][x]) {
					ss += s[i][x];
				}
				else {
					if (s[i][x] == 'S') {
						if (s[j][x] == 'E') {
							ss += 'T';
						}
						else if (s[j][x] == 'T') {
							ss += 'E';
						}
					}
					else if (s[i][x] == 'E') {
						if (s[j][x] == 'S') {
							ss += 'T';
						}
						else if (s[j][x] == 'T') {
							ss += 'S';
						}
					}
					else {
						if (s[j][x] == 'S') {
							ss += 'E';
						}
						else if (s[j][x] == 'E') {
							ss += 'S';
						}
					}
				}
			}
			if (ma[ss] > 0) {
				cnt += ma[ss];
			}
		}
	}
	cout << cnt / 3<< endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值