Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一直以为我的BST写的很挫,看了讨论,觉得还行。。1100ms#include <cstdio> #include <cstdlib> #include <cstring> using namespace std; struct TREE { int l,r,cs;bool fg;char str[40]; }T[2000010]; int cnt=1,num=1; char tree[40]; void copy(int u) { int len=strlen(tree); for(int i=0;i<len;i++) T[u].str[i]=tree[i]; } void insert(int u) { if(!T[u].fg) { copy(u); T[u].l=++cnt; T[u].r=++cnt; T[u].cs=1; T[u].fg=true; } else { int cp=strcmp(tree,T[u].str); if(cp<0) insert(T[u].l); else if(cp>0) insert(T[u].r); else T[u].cs++; } } void read() { gets(tree); copy(1); T[1].fg=true; T[1].l=++cnt; T[1].r=++cnt; T[1].cs=1; while(gets(tree)) { insert(1); num++; } } void prt(int u) { if(T[u].fg==0) return; prt(T[u].l); printf("%s %.4lf\n",T[u].str,double(T[u].cs)/double(num)*100.0); prt(T[u].r); } int main() { read(); prt(1); //system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator