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

老是TLE,哪位大神能帮我看看,不甚感激!

Posted by dennyhappy at 2011-07-15 18:01:19 on Problem 1002
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int readline(){
	int num=0,i,t,len;
	char a[50];
	int b[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
	scanf("%s",a);
	for(i=0,len=strlen(a);i<len;i++){
		if(a[i]!='-'){
			if(a[i]<'A') t=a[i]-48;
			else t=b[a[i]-'A'];
			num=10*num+t;
		}
	}
	return num;
}
int partition(int *p,int low,int high){
	int pivotkey;
	pivotkey=p[low];
	while(low<high){
		while(low<high && p[high]>=pivotkey) high--;
		p[low]=p[high];
		while(low<high && p[low]<=pivotkey) low++;
		p[high]=p[low];
	}
	p[low]=pivotkey;
	return low;
}
void Qsort(int *p,int low,int high){
	int pivot;
	if(low<high){
		pivot=partition(p,low,high);
		Qsort(p,low,pivot-1);
		Qsort(p,pivot+1,high);
	}
}
int main(){
	int i,j,n,t1,t2,flag,*array;
	scanf("%d",&n);
	array=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++){
		array[i]=readline();
	}
	Qsort(array,0,n-1);
//	for(i=0;i<n;i++) printf("%d\n",array[i]);
	for(i=0,j=1,flag=0;i<n-1;){
		while(array[i]==array[i+1]){ 
			i++;
			j++;
		}
		if(j>1){
			t1=array[i]/10000; 
			t2=array[i]-t1*10000;
			printf("%03d-%04d %d\n",t1,t2,j);
			flag=1;
			j=1;
		}
		i++;
	}
	if(flag==0) 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