图书列表
来源:互联网 发布:world of goo 破解mac 编辑:程序博客网 时间:2024/04/28 12:01
题目描述
模拟
这种题瞎模拟
我是建了个trie,对于图书和目录分开来存储。一个字符串用它在哈希表的位置作为数值。
然后输出的时候,把一个节点的儿子按字典序排序
#include<cstdio>#include<cstring>#include<algorithm>#include<map>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;typedef long long ll;typedef pair<int,int> pi;const int maxn=30*100*2+10,maxh=10000;map<int,int> g[maxn],f[maxn];int has[maxh+10],b[maxn];pi a[maxn];char ha[maxh+10][110],len[maxh+10],s[110],h[110];int i,j,k,l,t,n,m,tot,top,cnt,root;char ch,ch2;int getid(char ch){ if (ch>='A'&&ch<='Z') return ch-'A'+1; else if (ch>='0'&&ch<='9') return ch-'0'+27; else return 37;}bool cmp1(int x){ int i; if (top!=len[x]) return 0; fo(i,1,top) if (h[i]!=ha[x][i]) return 0; return 1;}int hash(){//get a string hash int i,j,k=0; fo(i,1,top) k=((ll)k*38%maxh+(ll)getid(h[i]))%maxh; if (!k) k=maxh; j=k; while (has[k]!=0&&(has[k]!=j||has[k]==j&&!cmp1(k))) k=k%maxh+1; if (!has[k]){ has[k]=j; fo(i,1,top) ha[k][i]=h[i]; len[k]=top; } return k;}void insert(int &x,int y){ if (!x) x=++tot; int i,j,k; fo(i,y,m) if (i==m||s[i]=='/') break; top=0; fo(j,y,i) h[++top]=s[j]; if (h[top]=='/') top--; k=hash(); if (i==m) f[x][k]=1; else insert(g[x][k],i+1);}char get(){ char ch2=getchar(); while ((ch2<'0'||ch2>'9')&&(ch2<'A'||ch2>'Z')&&ch2!=' '&&ch2!='/') ch2=getchar(); return ch2;}bool cmp3(int x,int y){ int i; /*if (len[x]<len[y]) return 1; if (len[x]>len[y]) return 0;*/ fo(i,1,min(len[x],len[y])) if (ha[x][i]<ha[y][i]) return 1; else if (ha[x][i]>ha[y][i]) return 0; if (len[x]<=len[y]) return 1;else return 0;}bool cmp2(pi a,pi b){ return cmp3(a.first,b.first);}bool cmp4(int x,int y){ return cmp3(x,y);}void write(int x,int y){ int i; fo(i,1,4*(y-1)) printf(" "); fo(i,1,len[x]) printf("%c",ha[x][i]); printf("\n");}void dfs(int x,int y){ int i,j,k,l,r; if (!g[x].empty()){ l=top+1; while (!g[x].empty()){ a[++top]=(*(g[x].begin())); g[x].erase(g[x].begin()); } r=top; sort(a+l,a+r+1,cmp2); fo(i,l,r){ write(a[i].first,y); dfs(a[i].second,y+1); } } if (!f[x].empty()){ cnt=0; while (!f[x].empty()){ b[++cnt]=(*(f[x].begin())).first; f[x].erase(f[x].begin()); } sort(b+1,b+cnt+1,cmp4); fo(i,1,cnt) write(b[i],y); }}int main(){ freopen("booklist.in","r",stdin);freopen("booklist.out","w",stdout); root=tot=1; while (1){ m=0; ch=get(); ch2=getchar(); if (ch=='0'&&(ch2<'0'||ch2>'9')&&(ch2<'A'||ch2>'Z')&&ch2!=' '&&ch2!='/') break; s[m=1]=ch; s[m=2]=ch2; while (1){ ch2=getchar(); if ((ch2<'0'||ch2>'9')&&(ch2<'A'||ch2>'Z')&&ch2!=' '&&ch2!='/') break; s[++m]=ch2; } insert(root,1); } dfs(root,1);}
0 0
- 图书列表
- 计算机图书列表
- CSDN技术图书列表
- Jzoj4834 图书列表
- 清华大学出版社书评征集图书列表
- C++的一些图书列表
- 爬取京东图书列表页图片
- 许多的图书下载连接列表
- 许多的图书下载连接列表
- 许多的图书下载连接列表
- 维护有序的图书列表_compateToIgnoreCase()方法
- 图书
- 图书
- 图书
- 图书
- 图书
- 图书
- 自定义UITableViewCell实现ibooks类似的图书列表形式
- String、StringBuffer、StringBuilder的区别?
- popwindow显示之后,退出当前activity出现阴影
- android webview ZoomButtonsController 导致android.view.WindowLeaked 问题彻底解决
- 二维数组与指向数组的指针
- 关于CoreData的增、删、改、查 (1)
- 图书列表
- CentOS 7.2 配置Apache服务(httpd)--上篇
- java8 stream 操作
- LeeCode 58. Length of Last Word 计算字符串的最后的一个单词的长度
- HTML5 Server-Sent Events with Java Servlets example
- new Gson().toJson(object) null值不进行转换问题
- 重庆市noip2016模拟round4 BSOJ4874 排序
- java中equals方法的用法和“==”的用法
- 分布式系统下的纠删码技术(一) -- Erasure Code (EC)