| ||||||||||
| 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 | |||||||||
版主大哥 我都改成快排了 怎么还是time limit exceeded 啊?帮帮我好吗 ?#include <stdio.h>
char in[1000000][50];
long n;
long out[1000000];
void quick(int low,int high)
{
int low1=low,high1=high,p;
if(low1<high1)
{
p=out[low1];
while (low1<high1)
{
while(low1<high1&&out[high1]>=p)
--high1;
out[low1]=out[high1];
while (low1<high1&&out[low1]<=p)
++low1;
out[high1]=out[low1];
}
out[low1]=p;
quick(low,low1-1);
quick(low1+1,high);
}
}
void change()
{
char c;
int i,j,k;
for(i=0;i<n;i++)
{
for(j=0,k=0;(c=in[i][j])!='\0';j++)
if(c>='0'&&c<='9')
k=k*10+c-'0';
else
switch(c)
{
case 'A':case 'B':case 'C': k=k*10+2; break;
case 'D':case 'E':case 'F': k=k*10+3; break;
case 'G':case 'H':case 'I': k=k*10+4; break;
case 'J':case 'K':case 'L': k=k*10+5; break;
case 'M':case 'N':case 'O': k=k*10+6; break;
case 'P':case 'R':case 'S': k=k*10+7; break;
case 'T':case 'U':case 'V': k=k*10+8; break;
case 'W':case 'X':case 'Y': k=k*10+9; break;
}
out[i]=k;
}
}
void prt()
{
int i,j,c,f=0;
int o[7];
for(i=0,c=1;i<n;i++)
{
if(out[i]==out[i+1])
c++;
else
if(c>1)
{
f=1;
for(j=0;j<7;j++)
{
o[j]=out[i]%10;
out[i]/=10;
}
for(j=6;j>=0;j--)
{
printf("%d",o[j]);
if(j==4)
printf("-");
}
printf(" %d\n",c);
c=1;
}
}
if(f==0)
printf("No duplicates.\n");
}
main()
{
int i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s",in[i]);
change();
quick(0,n-1);
prt();
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator