| ||||||||||
| 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 | |||||||||
总是TLE呀,哪位大牛帮我改一下,谢了#include<iostream>
using namespace std;
void qusort(char **p,int *num, int low ,int high);
int part(char **p,int *num,int low,int high);
int main()
{
int n,i,j;
scanf("%d",&n);
char p[20],**fin;
int *num,*finlen;
fin=new char*[n];
num=new int [n];
finlen=new int [n];
for(i=0;i<n;i++)
finlen[i]=0;
for( i=0;i<n;i++)
{
fin[i]=new char[8];
num[i]=1;
scanf("%s",p);
for(int k=0;p[k]!='\0';k++)
{
if(p[k]=='-')
continue;
if(p[k]>='0'&&p[k]<='9')
{ fin[i][finlen[i]]=p[k];
++finlen[i];
continue;
}
if(p[k]>='A'&&p[k]<='P')
{ fin[i][finlen[i]]=(p[k]-65)/3+50;
finlen[i]++;
continue;
}
if(p[k]>='R'&&p[k]<='Y')
{ fin[i][finlen[i]]=(p[k]-66)/3+50;
++finlen[i];
continue;
}
}
fin[i][finlen[i]]='\0';
}
delete []finlen;
int time=0;
for(int u=0;u<n;u++)
{
if(num[u]==0)
continue;
for(int k=u+1;k<n;k++)
if(strcmp(fin[u],fin[k])==0&&num[k]!=0)
{
num[u]++;
if(num[u]==2)
time++;
num[k]--;
}
}
if(time==0)
{
printf("No duplicates.\n");
return 0;
}
char ** w;
int *q;
w=new char*[time];
q=new int [time];
for(i=0;i<time;i++)
{
w[i]=new char [8];
for(j=0;j<n;j++)
if(num[j]>=2)
{
w[i]=fin[j];
q[i]=num[j];
num[j]=0;
break;
}
}
delete []fin;
delete []num;
qusort(w,q,0,time-1);
for(i=0;i<time;i++)
printf("%c%c%c-%s %d\n",w[i][0],w[i][1],w[i][2],w[i]+3,q[i]);
return 0;
}
void qusort(char **p,int *num, int low ,int high)
{
if(low <high)
{
int piv=part(p,num,low,high);
qusort(p,num,low,piv-1);
qusort(p,num,piv+1,high);
}
}
int part(char **p,int *num,int low,int high)
{
char *piv=new char[8];
piv=p[low];
int temp=num[low];
while(low <high)
{
while(low<high&&(strcmp(piv,p[high])<=0))
high--;
swap(p[low],p[high]);
swap(num[low],num[high]);
while(low <high&&(strcmp(piv,p[low])>=0))
low++;
swap(p[low],p[high]);
swap(num[low],num[high]);
}
return low;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator