Problem D accepts: 2806 submissions: 8458 time limit: 2000/1000 MS (Java/others) memory limit: 65536/65536 K (Java/others) Problem Description
The D country where DU Xiong lives is a country that fully respects human rights. So that everyone in this country has a very strange name. A person's name consists of several characters. Similarly, each character string in the result of these characters is also the name of this person. For example, if a person is named ACM, then AMC, Cam, Mac, MCA, and so on are also the names of this person. No one in this country has the same name.
Duxiong wants to count the population of this country. Please help duxiong design a program to count how many times each person has been counted before.
Input
This includes a group of test data. The first row contains a positive integer NN, And the next NN row represents the NN name. Nn will not exceed, 000, and their names will not exceed 40.
Output
For each input person name, an integer is output, which indicates how many times the person was previously counted.
Sample Input
5ACMMACBBAACMBAB
Sample output
01021
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <stack>#include <map>#include <algorithm>#include <set>using namespace std;typedef long long ll;typedef unsigned long long ull;#define MM(a,b) memset(a,b,sizeof(a));const double eps = 1e-10;const int inf =0x7f7f7f7f;const double pi=acos(-1);const int maxn=100+100000;map<ull,int> mp;char s[50];ull BKDRHash(char* s){ ull seed=133331; ull hashv=0; while(*s) { hashv=hashv*seed+(*s++); } return (hashv & 0x7FFFFFFF);}int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",s); int len=strlen(s); sort(s,s+len); ull k=BKDRHash(s); printf("%d\n",mp[k]); mp[k]++; } return 0;}
Analysis: map + hash: the hash value of the string is saved with map. Previously, the seed value is 133331, and so on. It is wrong. It is only used if it is changed ,,
Baidu star d map + hash