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

怎么还会超时呢,已经用快排了。

Posted by 412188290 at 2010-12-27 16:27:21 on Problem 1002
#include <stdio.h>
#include <string.h>
#define MAXSIZE 100
int a[100005],count[100005];
char s[100005][MAXSIZE];
void quicksort(int a[], int l, int r){
	int x,i,j,t;
	if(l<r){
		x=a[r]; i=l-1;
		for(j=l;j<=r-1;j++){
			if(a[j]<=x){
				i++;
				t=a[i]; a[i]=a[j]; a[j]=t;
			}
		}
		t=a[i+1]; a[i+1]=a[r]; a[r]=t;
		quicksort(a,l,i);
		quicksort(a,i+2,r);
	}
}
int main(){
	int n,i=1,t,j,d,k=1,slen,f=0;
	scanf("%d",&n);
	while(n&&scanf("%s",s[i])!=EOF) { i++; n--; }
	t=i-1;
	for(i=1;i<=t;i++){
		slen=strlen(s[i]);
		d=1000000;
		for(j=0;j<slen;j++){
			if('0'<=s[i][j]&&s[i][j]<='9') { a[i]+=(s[i][j]-'0')*d; d/=10; }
			if('A'<=s[i][j]&&s[i][j]<='Z'){
				switch(s[i][j]){
					case 'A': case 'B': case 'C': a[i]+=('2'-'0')*d; break;
					case 'D': case 'E': case 'F': a[i]+=('3'-'0')*d; break;
					case 'G': case 'H': case 'I': a[i]+=('4'-'0')*d; break;
					case 'J': case 'K': case 'L': a[i]+=('5'-'0')*d; break;
					case 'M': case 'N': case 'O': a[i]+=('6'-'0')*d; break;
					case 'P': case 'R': case 'S': a[i]+=('7'-'0')*d; break;
					case 'T': case 'U': case 'V': a[i]+=('8'-'0')*d; break;
					case 'W': case 'X': case 'Y': a[i]+=('9'-'0')*d; break;
					default : break;
				}
				d/=10;
			}
		}
	}
	quicksort(a,1,t);
	for(i=1;i<=t;){
		j=i+1;
		while(a[i]==a[j]){ 
			count[i]++; j++; 
		}
		i=j;
	}
	for(j=1;j<=t;j++){
		if(count[j]){
			if(a[j]/10000>999&&a[j]%10000>999) printf("%d-%d ",a[j]/10000,a[j]%10000);
			if(a[j]/10000>99) printf("%d-",a[j]/10000);
			else if(a[j]/10000<100&&a[j]/10000>9) printf("0%d-",a[j]/10000);
			else printf("00%d-",a[j]/10000);
			if(a[j]%10000>999) printf("%d ",a[j]%10000);
			else if(a[j]%10000<1000&&a[j]%10000>99) printf("0%d ",a[j]%10000);
			else if(a[j]%10000<100&&a[j]%10000>9) printf("00%d ",a[j]%10000);
			else if(a[j]%10000<10) printf("000%d ",a[j]%10000);
			printf("%d\n",count[j]+1);
			f=1;
		}
	}
	if(!f) printf("No duplicates.\n");
	return 0;
}


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