| ||||||||||
| 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 | |||||||||
Re:呜呜呜,优化了以后还是超时,哪位大虾指点下?In Reply To:呜呜呜,优化了以后还是超时,哪位大虾指点下? Posted by:00448175 at 2005-04-29 23:25:27 假如不用cin/cout的话说不定就过了
> #include<iostream.h>
> #include<string.h>
> #include<iomanip.h>
> #include<stdlib.h>
> char tree[1000000][30];
> int count[10000];
> int compare(const void *a,const void *b){
> return(strcmp((char*)a,(char*)b));
> }
> int cmp(char *a,char *b){
> for(int i=0;*(a+i)!='\0'||*(b+i)!='\0';i++)
> if(*(a+i)!=*(b+i))return 0;
> return 1;
> }
> void main()
> {
> int i=0,j=0,k=0;
> while(cin.getline(tree[i],30))
> i++;
> qsort(tree,i,sizeof(tree[0]),compare);
> int flags=0;
> double num=1;
> double jump=0.5;
> for(j=0;j<i;){
> for(k=0;;k++){
> jump*=2;
> if(cmp(tree[j],tree[j+int(jump)])==1)
> continue;
> else break;
> }
> if(jump==1){
> cout<<tree[j]<<" ";
> cout<<setiosflags(ios::fixed);
> cout<<setprecision(4)<<num*100/i<<endl;
> j++;
> jump=0.5;
> num=1;
> continue;
> }
> num+=int(jump/2);
> j+=int(jump/2);
> jump=0.5;
> }
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator