bzoj3555 Penguin QQ

Source: Internet
Author: User

3555: [Ctsc2014] Penguin qq time limit:20 Sec Memory limit:256 MB
submit:1640 solved:613 Description

PENGUINQQ is China's largest and most influential SNS (social Networking Services) website, based on the real name, to provide users with logs, groups, instant messaging, photo albums, markets and other rich and powerful Internet functionality experience, to meet users of social, information, entertainment, Transactions and other aspects of demand.
Little Q is the administrator of the PENGUINQQ website, who recently conducted an interesting study-which accounts are registered with the same person. After a long period of analysis, small q found that the same person registered account name is always very similar, such as penguin1,penguin2,penguin3 ... So the small Q decided to make a statistical analysis of this similar situation first.
A small Q definition, if two account names are similar, when and only if the two strings are equal and only one bit different. For example "Penguin1" and "Penguin2" are similar, but "Penguin1" and "2Penguin" are not similar. And little Q wants to know how many pairs are similar in a given account name.
To simplify your work, the string length that small q gives you is equal to and contains only uppercase and lowercase letters, numbers, underscores, and ' @ ' a total of 64 characters, and there are no two identical account names.

Input

The first line contains three positive integers,. It represents the number of account names, indicating the length of the account name, used to indicate the size of the character set, and its value can only be 2 or 64.
If equal to 2, the account name contains only the characters ' 0 ' and ' 1 ' of 2 characters;
If equal to 64, the account name may contain uppercase and lowercase letters, numbers, underscores, and ' @ ' a total of 64 characters.
Subsequent lines, one string of length per line, are used to describe an account name. The data guarantees that a string is 22 different.

Output

A single positive integer that indicates how many pairs of similar account names are in common.

Sample Input4 3 64
Fax
Fax
Max
MacSample Output4HINT

4 pairs of similar strings are: Fax with Fax,fax and Max,fax with Max,max and Mac. N<=30000,l<=200,s<=64

String hash

First do a hash table, and then enumerate each of the different cases, the total hash value minus the hash value of this bit after sorting, calculate the logarithm of the same result

At first, I didn't notice that Unsigned,wa had a face, 233

1 /**/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 using namespacestd;8 Const intmxn=30010;9 Const intp=131;Ten intN,len; One intans=0; A Chars[mxn][ About]; - //Hash -UnsignedLong Longpw[ About],H[MXN],NH[MXN]; the // - voidHash () { -      for(intI=1; i<=n;i++) -        for(intj=1; j<=len;j++){ +h[i]=h[i]*p+S[i][j]; -       } +     return; A } at intMain () { -pw[0]=1; -     inti,j; -      for(i=1;i<203; i++) pw[i]=pw[i-1]*p; -scanf"%d%d%*d", &n,&len);//the function of%*d is to read but not store, that is to skip this data -      for(i=1; i<=n;i++){ inscanf"%s", s[i]+1); -     } to hash (); +      for(j=1; j<=len;j++) {//number of enumeration bits -          for(i=1; i<=n;i++){ thenh[i]=h[i]-s[i][j]*pw[len-j]; *         } $Sort (nh+1, nh+n+1);Panax Notoginseng         inttmp=1; -          for(i=2; i<=n;i++){ the             if(nh[i-1]==Nh[i]) { +ans+=tmp; Atmp++; the             } +             Elsetmp=1; -         } $     } $printf"%d\n", ans); -     return 0; -}

bzoj3555 Penguin QQ

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.