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 |
Re:请发给我一个吧,我写了 1500B的代码才 109ms的,想学学高效算法In Reply To:请发给我一个吧,我写了 1500B的代码才 109ms的,想学学高效算法 Posted by:sunmoonstar_love at 2005-08-24 01:43:26 int da[50001]; int main() { int i,j,m,n,p; while (scanf("%d",&n)!=EOF) { for (i=1;i<=n;i++) scanf("%d",&da[i]); for (i=1,m=-1;i+m<n;i++) { //加了"+m"二个字符,汗.. p=i; for (j=i+1;j<=n;j++) if (da[j]<da[i]) break; else if (da[j]>da[p]) p=j; if (p-i>m) m=p-i; } if (m==0) m=-1; printf("%d\n",m); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator