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 <stdio.h> #include <malloc.h> int judge (int *a,int hop) { int i=0; int left=0; int locate=0; for (i=1;i<=*a;i++) *(a+i)=0; left=*a/2; i=hop; locate=1; while (left>=1) { if (*(a+locate)==1) { locate++; if (locate>*a) locate=1; continue; } if (i>1) { i--; locate++; if (locate>*a) locate =1; continue; } if (locate>*a/2) { left--; *(a+locate)=1; i=hop; locate++; if (locate>*a) locate=1; continue; } return (0); } return (1); } void main () { int *a; int num=0; int i=0; scanf ("%d",&num); while ((num>0)&&(num<14)) { a= (int*)( malloc( sizeof(int)*(2*num+1) )); *a=2*num; for (i=num+1;!judge(a,i);i++); printf ("%d\n",i); free(a); scanf ("%d",&num); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator