| ||||||||||
| 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 | |||||||||
本题优化才能更节约时间??(付代码)该程序的内存使用是408K,运行时间是93ms,请教如何才能使时间更少?
#include<stdio.h>
#include<malloc.h>
int isAm(int *a,int n)
{
int i; int flag =1;
for(i=0; i<n;i++)
{
if(a[a[i]-1] != (i+1)) return 0;
}
return flag;
}
int main()
{
int n,i;
int *a;
while( scanf("%d",&n) != EOF)
{
if(n == 0) break;
a = (int*)calloc(n,sizeof(int));
for(i=0;i<n;i++) scanf("%d",&a[i]);
if(isAm(a,n)) printf("ambiguous\n");
else printf("not ambiguous\n");
free(a);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator