HDU 5688 (hash)
2016-05-17 18:04
337 查看
Problem D
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 108 Accepted Submission(s): 78
Problem Description
度熊所居住的 D 国,是一个完全尊重人权的国度。以至于这个国家的所有人命名自己的名字都非常奇怪。一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每一个字符串,也都是这个人的名字。例如,如果一个人名字是 ACM,那么 AMC, CAM, MAC, MCA, 等也都是这个人的名字。在这个国家中,没有两个名字相同的人。
度熊想统计这个国家的人口数量,请帮助度熊设计一个程序,用来统计每一个人在之前被统计过多少次。
Input
这里包括一组测试数据,第一行包含一个正整数N,接下来的N 行代表了 N 个名字。N 不会超过100,000,他们的名字不会超过40位.
Output
对于每输入的一个人名,输出一个整数,代表这个人之前被统计了多少次。
Sample Input
5
ACM
MAC
BBA
ACM
BAB
Sample Output
0
1
0
2
1
给每个字符串排个序相当于求之前相等串的个数,直接hash把hash值扔进map就好
了。
#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
#define maxn 1111111
typedef unsigned long long ull;
map <ull, int> gg;
char a[44];
int n;
ull f (char a) {
return a-'a'+1;
}
int main () {
//freopen ("in.txt", "r", stdin);
scanf ("%d", &n);
gg.clear ();
for (int i = 1; i <= n; i++) {// cout << i << endl;
scanf ("%s", a);
int l = strlen (a);
sort (a, a+l);
ull num = 1;
for (int i = 0; i < l; i++) {
num = num*131+f (a[i]);
} //cout << num << endl;
if (gg.count (num)) {
printf ("%d\n", gg[num]);
}
else {
printf ("0\n");
}
gg[num]++;
}
return 0;
}
相关文章推荐
- kudu compaction design
- python 爬取煎蛋网图片
- Unable to connect to a repository at URL '': authorization failed: Could not authenticate to server:
- centos6.7环境半虚拟化软件xen及xm配置工具使用详解
- 安卓webview html5 自动播放本地视频,网上视频,可以循环播放
- centos6.7环境半虚拟化软件xen及xm配置工具使用详解
- C#中ICollection介绍
- Scrum第一天任务认领情况
- 12个JavaScript技巧
- 拖拽排序Tabs的实现
- 【CF 675D】 Tree Construction(离线二分+左右指针)
- cookie对象
- 在嵌入式学习困惑:做驱动开发还是做应用开发更有前途
- PSI信息解析
- 120. Triangle
- shell-printf命令详解
- APKTOOL的使用心得
- SpringMVC源代码学习(六)HanderMapping详解
- poj 2000 金币(递推)
- 几篇调试IIS内存过高或CPU过高的好文章