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 ahxgw at 2009-07-25 17:08:04 on Problem 1002
#include<stdio.h>

void swap(int *x,int *y)
{
	int temp;

	temp=*x;
	*x=*y;
	*y=temp;
}

void quick(int l,int u,int a[])
{
	int l1=l,u1=u,m=a[l];

	if(l>=u)
		return;
	while(l1<u1)
	{
		for(;u1>l1;u1--)
			if(m>a[u1])
			{
				swap(&a[l1],&a[u1]);
				break;
			}
		for(;u1>l1;l1++)
			if(m<a[l1])
			{
				swap(&a[l1],&a[u1]);
				break;
			}
	}
	quick(l,u1-1,a);
	quick(l1+1,u,a);
}

void main()
{
	int n,i,k,a[100000]={0},j,temp,sum=0;
	char bu[41];
	int c[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};
	int d[7];

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",bu);
		j=-1;
		while(bu[++j])
		{
			if(bu[j]=='-')
				continue;
			else if(bu[j]>='0'&&bu[j]<='9')
				a[i]=a[i]*10+bu[j]-'0';
			else
				a[i]=a[i]*10+c[bu[j]-'A'];
		}
	}
	quick(0,n-1,a);
	temp=a[0];
	k=1;
	for(i=1;i<n;i++)
		if(temp!=a[i]||i==n-1)
		{
			if(temp==a[i])
				k++;
			if(k>1)
			{
				for(j=0;j<7;j++)
				{
					d[j]=temp%10;
					temp/=10;
				}
				printf("%d%d%d-%d%d%d%d %d\n",d[6],d[5],d[4],d[3],d[2],d[1],d[0],k);
				sum++;
			}
			temp=a[i];
			k=1;
		}
		else
			k++;
		if(sum==0)
			printf("No duplicates.\n");
}

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