309372: CF1669E. 2-Letter Strings

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:5 Solved:0

Description

2-Letter Strings

题意翻译

题目描述: 你被给予了$n$个长度为2的字符串,每个含有从$a$到$k$的小写字母。找出所有对$(i,j)$使得$i<j$并且第$i$个字符串和第$j$个字符串**刚好**有1个字符不同。 换句话来说,找到所有的数字对$(i,j)(i<j)$使得第$i$个字符串与第$j$个字符串有唯一一个数字$p(1 \leq p \leq 2)$使得$s_{i_p}\neq s_{j_p}$ 答案可能超出32位数的范围,所以你在使用c++时应该使用long long等64位变量类型来存储数据避免溢出 注:本题有多数据 输入格式: 第一行输入一个整数$t(1\leq t \leq 100)$表示测试组数 每个测试组的第一行输入一个整数$n(1\leq n \leq 10^5)$,意义在上面 接下来的$n$行每行输入一个2字符长的字符串$s_i$,只包含字符$a$到$k$。 数据保证$n$的总和不超过$10^5$ 输出格式: 对于每一个测试组,输出一个表示数字对的个数,条件在背景里 ##### 重复一遍(?):答案可能超出32位数的范围,所以你在使用c++时应该使用long long等64位变量类型来存储数据避免溢出 说明/提示 对于第一个测试样例,符合的字符串对为: ("ab", "cb"), ("ab", "db"), ("ab", "aa"), ("cb", "db") 和 ("cb", "cc")。 对于第二个测试样例,符合的字符串对为: ("aa", "ac"), ("aa", "ca"), ("cc", "ac"), ("cc", "ca"), ("ac", "aa") 和 ("ca", "aa")。 对于最后一个测试样例,没有一种情况符合

题目描述

Given $ n $ strings, each of length $ 2 $ , consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $ (i, j) $ such that $ i < j $ and the $ i $ -th string and the $ j $ -th string differ in exactly one position. In other words, count the number of pairs $ (i, j) $ ( $ i < j $ ) such that the $ i $ -th string and the $ j $ -th string have exactly one position $ p $ ( $ 1 \leq p \leq 2 $ ) such that $ {s_{i}}_{p} \neq {s_{j}}_{p} $ . The answer may not fit into 32-bit integer type, so you should use 64-bit integers like long long in C++ to avoid integer overflow.

输入输出格式

输入格式


The first line of the input contains a single integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ) — the number of strings. Then follows $ n $ lines, the $ i $ -th of which containing a single string $ s_i $ of length $ 2 $ , consisting of lowercase Latin letters from 'a' to 'k'. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式


For each test case, print a single integer — the number of pairs $ (i, j) $ ( $ i < j $ ) such that the $ i $ -th string and the $ j $ -th string have exactly one position $ p $ ( $ 1 \leq p \leq 2 $ ) such that $ {s_{i}}_{p} \neq {s_{j}}_{p} $ . Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

输入输出样例

输入样例 #1

4
6
ab
cb
db
aa
cc
ef
7
aa
bb
cc
ac
ca
bb
aa
4
kk
kk
ab
ab
5
jf
jf
jk
jk
jk

输出样例 #1

5
6
0
6

说明

For the first test case the pairs that differ in exactly one position are: ("ab", "cb"), ("ab", "db"), ("ab", "aa"), ("cb", "db") and ("cb", "cc"). For the second test case the pairs that differ in exactly one position are: ("aa", "ac"), ("aa", "ca"), ("cc", "ac"), ("cc", "ca"), ("ac", "aa") and ("ca", "aa"). For the third test case, the are no pairs satisfying the conditions.

Input

题意翻译

题目描述: 你被给予了$n$个长度为2的字符串,每个含有从$a$到$k$的小写字母。找出所有对$(i,j)$使得$i<j$并且第$i$个字符串和第$j$个字符串**刚好**有1个字符不同。 换句话来说,找到所有的数字对$(i,j)(i<j)$使得第$i$个字符串与第$j$个字符串有唯一一个数字$p(1 \leq p \leq 2)$使得$s_{i_p}\neq s_{j_p}$ 答案可能超出32位数的范围,所以你在使用c++时应该使用long long等64位变量类型来存储数据避免溢出 注:本题有多数据 输入格式: 第一行输入一个整数$t(1\leq t \leq 100)$表示测试组数 每个测试组的第一行输入一个整数$n(1\leq n \leq 10^5)$,意义在上面 接下来的$n$行每行输入一个2字符长的字符串$s_i$,只包含字符$a$到$k$。 数据保证$n$的总和不超过$10^5$ 输出格式: 对于每一个测试组,输出一个表示数字对的个数,条件在背景里 ##### 重复一遍(?):答案可能超出32位数的范围,所以你在使用c++时应该使用long long等64位变量类型来存储数据避免溢出 说明/提示 对于第一个测试样例,符合的字符串对为: ("ab", "cb"), ("ab", "db"), ("ab", "aa"), ("cb", "db") 和 ("cb", "cc")。 对于第二个测试样例,符合的字符串对为: ("aa", "ac"), ("aa", "ca"), ("cc", "ac"), ("cc", "ca"), ("ac", "aa") 和 ("ca", "aa")。 对于最后一个测试样例,没有一种情况符合

加入题单

算法标签: