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 |
俩代码~~这里的速度还可以~~为啥一上百炼就悲剧了呢?3468K 735MS 百炼上TLE了 #include<cstdio> #include<cstring> int n,i,x,k; char c[50],e[9],d[27]="22233344455566677778889999"; struct t { char c[9]; int n; t *l; t *r; }*h=NULL; void p(t *&s) { if(s==NULL){ s=new t; strcpy(s->c,e); s->n=1; s->l=NULL; s->r=NULL; } else if(strcmp(s->c,e)==0)s->n++; else if(strcmp(s->c,e)>0)p(s->l); else p(s->r); } bool l(t *&s) { bool b=0; if(s->l!=NULL){if(l(s->l))b=1;} if(s->n>1){printf("%s %d\n",s->c,s->n);b=1;} if(s->r!=NULL)if(l(s->r))b=1; return b; } int main() { scanf("%d",&n); e[8]='\0'; while(n--){ x=0;k=0; scanf("%s",c); for(i=0;i<strlen(c);i++)if(c[i]!='-'){ if(c[i]>='A'&&c[i]<='Z')e[k]=d[(c[i]-'A')]; else e[k]=c[i]; k++; if(k==3){e[k]='-';k++;} } p(h); } if(!l(h))printf("No duplicates.\n"); } 39348K 454MS 这个过了,但看看内存,无地自容啊~~ #include<cstdio> #include<cstring> int n,a[10000000]={0},i,x,k; char c[20],d[27]="22233344455566677778889999"; int main() { scanf("%d",&n); while(n--){ x=0; scanf("%s",c); i=strlen(c); for(k=0;k<i;k++)if(c[k]!='-'){ if(c[k]>='A'&&c[k]<='Z')x=x*10+d[(c[k]-'A')]-'0'; else x=x*10+c[k]-'0'; } a[x]++; } k=1; for(i=0;i<10000000;i++)if(a[i]>1){k=0;printf("%03d-%04d %d\n",i/10000,i%10000,a[i]);} if(k)printf("No duplicates.\n"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator