Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:呜呜呜,优化了以后还是超时,哪位大虾指点下?

Posted by 00403022 at 2005-04-30 00:05:58 on Problem 2418
In Reply To:呜呜呜,优化了以后还是超时,哪位大虾指点下? Posted by:00448175 at 2005-04-29 23:25:27
> #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator