| ||||||||||
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 |
求教。为什么会超时?#include<cstdio> int a[1000],n; int ok() { int i,top=0,k=1; int stack[1000]; for(i=1;i<=n;i++) { stack[++top]=i; while(top&&stack[top]==a[k]) { top--; k++; } } if(top) return 0; else return 1; } int main() { int f=0,i; while(scanf("%d",&n),n) { if(f) printf("\n"); f=1; while(scanf("%d",&a[1]),a[1]) { for(i=2;i<=n;i++) scanf("%d",&a[i]); if(ok()) printf("Yes\n"); else printf("No\n"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator