3555: [Ctsc2014] penguin QQ, 3555ctsc2014

Source: Internet
Author: User

3555: [Ctsc2014] penguin QQ, 3555ctsc2014

3555: [Ctsc2014] penguin QQTime Limit: 20 Sec Memory Limit: 256 MB
Submit: 2691 Solved: 944
[Submit] [Status] [Discuss] Description

PenguinQQ is China's largest and most influential SNS (Social Networking Services) website, based on the real name system, it provides users with rich and powerful Internet function experiences such as logs, groups, instant messaging, photo albums, and marketplaces to meet their needs for social networking, information, entertainment, and transactions.
Xiao Q is the administrator of PenguinQQ. He is conducting an interesting study recently-which accounts are registered by the same person. After a long analysis, Xiao Q found that the account names registered by the same person are always very similar, such as Penguin1, Penguin2, Penguin3 ...... Therefore, Xiao Q decided to make statistics on this similar situation first.
If the two account names are similar, and only when the two strings are equal and only one character is different. For example, "Penguin1" is similar to "Penguin2", but "Penguin1" is not similar to "2Penguin. Q wants to know how many pairs are similar in a given account name.
To simplify your work, Q gives you a string of the same length and only contains 64 characters including uppercase/lowercase letters, numbers, underscores, and, there are no two identical account names.

Input

The first line contains three positive integers ,,. It indicates the number of account names, indicating the length of the account name, which is used to indicate the size of the character set. Its value may only be 2 or 64.
If it is equal to 2, the account name only contains two types of characters: '0' and '1;
If the value is 64, the account name may contain 64 characters including uppercase and lowercase letters, numbers, underscores, and.
Next line, each line contains a string to describe an account name. Data guarantees that strings are different from each other.

Output

There is only one positive integer in a row, indicating the number of pairs of similar account names.

Sample Input4 3 64
Fax
Fax
Max
MacSample Output4HINT

 

4 pairs of similar strings: Fax, fax, Fax, and max, fax, and max, and mac. N <= 30000, L <= 200, S <= 64

 

Source [Submit] [Status] [Discuss]
HOME Back

 

Bare question of string hash,

We can enumerate every bit of each string,

Delete him, and then count the number of solutions.

 

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <cstring> 6 # include <algorithm> 7 # include <map> 8 # define lli long int 9 # define ull unsigned long 10 using namespace std; 11 const int MAXN = 30001; 12 int seed = 27; 13 void read (int & n) 14 {15 char c = '+'; int x = 0; bool flag = 0; 16 while (c <'0' | c> '9') {c = getchar (); if (c = '-') flag = 1;} 17 while (c> = '0' & c <= '9') x = x * 10 + C-48, c = getchar (); 18 n = flag = 1? -X: x; 19} 20 int n, m, meiyong; 21 ull bghash [MAXN] [201]; 22 ull edhash [MAXN] [201]; 23 char a [MAXN]; 24 ull tmp [MAXN]; 25 int ans = 0; 26 void calc (int num) 27 {28 for (int I = 1; I <= m; I ++) bghash [num] [I] = bghash [num] [I-1] * (149) + a [I]; 29 for (int I = m; I> = 1; I --) edhash [num] [I] = edhash [num] [I + 1] * (137) + a [I]; 30} 31 int main () 32 {33 read (n); read (m); read (meiyong); 34 for (int I = 1; I <= n; I ++) 35 {36 scanf ("% s", a + 1); 37 calc (I); 38} 39 for (int I = 1; I <= m; I ++) // enumerate every bit 40 {41 for (int j = 1; j <= n; j ++) // enumerate every string 42 tmp [j] = (bghash [j] [I-1] * 233 + edhash [j] [I + 1] * 213 ); 43 sort (tmp + 1, tmp + n + 1); 44 int now = 1; 45 for (int j = 2; j <= n; j ++) 46 if (tmp [j] = tmp [J-1]) ans + = now, now ++; 47 else now = 1; 48} 49 printf ("% d ", ans); 50 return 0; 51}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.