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 |
为什么会Output Limit Exceeded?#include<stdio.h> #define MAX 50000 struct Record { long int value; long int position; }; long int findOut(long int *p,long int n,struct Record *q) { long int i,j,m,sum=0; q[0].value=p[0]; q[0].position=0; i=1; j=1; while(1) { for(;i<n;i++) //寻找 if(q[j-1].value<p[i]) { q[j].value=p[i]; q[j].position=i; j++; } if(j>=5) //计算 sum+=j*(j-1)*(j-2)*(j-3)*(j-4)/120; while(j>0) //退位 { j--; for(m=q[j].position+1;m<n&&(p[m]<q[j-1].value||p[m]>q[j].value);m++); if(m<n) { q[j].value=p[m]; q[j].position=m; i=m+1; j++; break; } } if(j==0) { for(m=q[0].position+1;m<n-4&&p[m]>q[j].value;m++); if(m<n-4) { q[0].value=p[m]; q[0].position=m; i=m+1; j++; } else break; } } return(sum); } void main() { long int i,N,sum; long int inPutNum[MAX]; struct Record record[MAX]; scanf("%ld",&N); while(N>0&&N<=MAX) { for(i=0;i<N;i++) scanf("%ld",&inPutNum[i]); sum=findOut(inPutNum,N,record); printf("%ld\n",sum); scanf("%ld",&N); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator