2020-4 codeforces B. Hyperset

        B. Hyperset
      time limit per test3 seconds
     memory limit per test256 megabytes
    inputstandard input
     outputstandard output

Bees Alice and Alesya gave beekeeper Polina famous card game “Set” as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.

在这里插入图片描述

Polina came up with a new game called “Hyperset”. In her game, there are n cards with k features, each feature has three possible values: “S”, “E”, or “T”. The original “Set” game can be viewed as “Hyperset” with k=4.

Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.

Unfortunately, winter holidays have come to an end, and it’s time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.

Input
The first line of each test contains two integers n and k (1≤n≤1500, 1≤k≤30) — number of cards and number of features.

Each of the following n lines contains a card description: a string consisting of k letters “S”, “E”, “T”. The i-th character of this string decribes the i-th feature of that card. All cards are distinct.

Output
Output a single integer — the number of ways to choose three cards that form a set.

Examples
inputCopy
3 3
SET
ETS
TSE
outputCopy
1
inputCopy
3 4
SETE
ETSE
TSES
outputCopy
0
inputCopy
5 4
SETT
TEST
EEET
ESTE
STES
outputCopy
2
Note
In the third example test, these two triples of cards are sets:

“SETT”, “TEST”, “EEET”
“TEST”, “ESTE”, “STES”

1.由数据大小猜测是否可以暴力解决。先选出前两个,然后由题中特点确定第三个。

#include<iostream>
#include<map>
using namespace std;
int main() {
	int n, k,ans=0;
	const int SET = 'S' + 'E' + 'T';
	string s1[1502];
	map<string, int> vis;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> s1[i];
		vis[s1[i]]++;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			string s2="";
			for (int p = 0; p < k; p++) {
				if (s1[i][p] == s1[j][p]) s2 += s1[j][p];
				else s2 += SET - s1[i][p] - s1[j][p];
			}
			if (vis.count(s2)) ans+=vis[s2];
		}
	}
	cout << ans / 3 << endl;
	return 0;
}


您提供的链接是Codeforces的一个问题,问题编号为104377。Codeforces是一个知名的在线编程竞赛平台,经常举办各种编程比赛和训练。Gym是Codeforces的一个扩展包,用于组织私人比赛和训练。您提供的链接指向了一个问题的页面,但具体的问题内容和描述无法通过链接获取。如果您有具体的问题或需要了解关于Codeforces Gym的更多信息,请提供更详细的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [http://codeforces.com/gym/100623/attachments E题](https://blog.csdn.net/weixin_30820077/article/details/99723867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [http://codeforces.com/gym/100623/attachments H题](https://blog.csdn.net/weixin_38166726/article/details/99723856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [CodeforcesPP:Codeforces扩展包](https://download.csdn.net/download/weixin_42101164/18409501)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值