合并子目录(hash)

时间:2023-03-09 07:44:19
合并子目录(hash)

题目2 : 合并子目录

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

小Hi的电脑的文件系统中一共有N个文件,例如:

/hihocoder/offer22/solutions/p1

/hihocoder/challenge30/p1/test

/game/moba/dota2/uninstall

小Hi想统计其中一共有多少个不同的子目录。上例中一共有8个不同的子目录:

/hihocoder

/hihocoder/offer22

/hihocoder/offer22/solutions

/hihocoder/challenge30

/hihocoder/challenge30/p1

/game

/game/moba

/game/moba/dota2/

输入

第一行包含一个整数N (1 ≤ N ≤ 10000)

以下N行每行包含一个字符串,代表一个文件的绝对路径。保证路径从根目录"/"开始,并且文件名和目录名只包含小写字母和数字。

对于80%的数据,N个文件的绝对路径长度之和不超过10000

对于100%的数据,N个文件的绝对路径长度之和不超过500000

输出

一个整数代表不同子目录的数目。

样例输入

3
/hihocoder/offer22/solutions/p1
/hihocoder/challenge30/p1/test
/game/moba/dota2/uninstall

样例输出

8

//看似挺复杂的,其实,用简单的方法做即可,hash,万一冲突了,换个权,再来一次,哈哈,学到了

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define LL long long
#define lowbit(x) ((x)&(-x))
#define PI acos(-1.0)
#define INF 0x3f3f3f3f3f3f3f3f
#define eps 1e-8
#define MOD 1000000007 inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 500005
/**************************/ set<LL>ss;
char s[MX]; int main ()
{
int n;
scanf("%d",&n);
for (int i=;i<=n;i++)
{
scanf("%s",s);
LL _hash=;
for (int i=; s[i]; ++i) {
if (s[i]=='/') ss.insert(_hash);
_hash=_hash*+s[i];
}
}
printf("%d\n",ss.size());
return ;
}