讨论 / C语言求解 WA50,后面5个测试点超时?
kwatch 2017-03-24 15:41:08
点我顶贴 收藏 删除
#include<stdio.h>

int main()

{

int n;

int k;

int i,j;

scanf("%d%d",&n,&k);

int E[11];

int W[n+1],D[n+1],C[n+1],B[n+1];

for(i=1;i<=10;i++) scanf("%d",&E[i]);

for(i=1;i<=n;i++)

{

scanf("%d",&W[i]);

B[i]=i;

}

int temp;

int num;

for(j=1;j<=n-1;j++)

for(i=1;i<=n-j;i++)

if(W[i]<W[i+1])

{

temp=W[i];

W[i]=W[i+1];

W[i+1]=temp;

num=B[i];

B[i]=B[i+1];

B[i+1]=num;

}

for(i=1;i<=n;i++)

{

D[i]=i;

C[i]=(D[i]-1)%10+1;

}

for(i=1;i<=n;i++)

W[i]=W[i]+E[C[i]];

for(j=1;j<=n-1;j++)

for(i=1;i<=n-j;i++)

{

if(W[i]<W[i+1])

{

temp=W[i];

W[i]=W[i+1];

W[i+1]=temp;

num=B[i];

B[i]=B[i+1];

B[i+1]=num;

}

else if (W[i]==W[i+1]&&B[i]>B[i+1])

{

temp=W[i];

W[i]=W[i+1];

W[i+1]=temp;

num=B[i];

B[i]=B[i+1];

B[i+1]=num;

}

}

for(i=1;i<=k;i++) printf("%d ",B[i]);

}

#1 Magna_Medivh@2017-07-27 22:57:23
回复 删除
Use an O(nlogn) method of sorting.
#2 舒服的红心枕头@2017-10-19 08:36:57
回复 删除
加油
查看更多回复
提交回复