for(;flag[k];k++);
you are searching the first k such that flag[k] is not set from
whatever a lower bound:
for(k=lower_bound; flag[k]; k++)
or more readable:
for(k=lower_boud; ; k++)
{
if(flag[k]==0)
{
break;
}
}
This lower_bound is indeterminate and it is possible you have to
search O(n) times here.
[此贴子已经被作者于2007-9-16 13:57:26编辑过]
这个比我先前那个明显好很多.但是速度也就快10几.
#include<stdio.h>
int main()
{
unsigned long n,m,sum;
int i,j,k;
while(scanf("%u%u",&n,&m)!=EOF)
{
if(n==-1&&m==-1) break ;
k=1;
for(i=1;i<=n;i++)
{
sum=(n-i)*(n-i-1)/2;
if(sum>=m)
{
printf("%d ",i);
}
else
{
m=m-sum+i;
printf("%d ",m);
break;
}
}
for(j=n;j>=i;j--)
{
if(j==m) continue;
printf("%d ",j);
}
printf("\n");
}
return 0;
}