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 |
我开始比你还暴力,后来改进的 可是还是超时,都优化了一晚上In Reply To:头次碰到超内存。贴个代码,用链表做的。各位大牛有什么方法能改进吗 Posted by:BGW991111 at 2010-03-19 15:10:48 #include <stdio.h> int main() { int K, temp, n, j, flag; long m; while(1) { scanf("%d",&K); if(!K) return 0; for(m=2*K-1;;m++) { temp=2*K; n=0; flag=0; j=(m-1)%(temp); while(1) { if(j<K) break; else { temp--; n++; j=(j-1+m)%temp; if(n>=K) { printf("%ld\n",m); flag=1; break; } } } if(flag) break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator