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:有没有好的算法啊?In Reply To:有没有好的算法啊? Posted by:german at 2004-05-27 20:27:10 我的算法0.3秒 应该有更好的算法 #include<iostream.h> bool check(int i,int j) { int start=1; int x; int leng=2*i; for(x=1;x<=i;x++) { start=(start+j-1)%leng; if(start==0) start=leng; leng--; if(start<=i) return false; if(start>leng) start=1; } return true; } main() { int a[15]; int i,j; for(i=1;i<14;i++) { for(j=i+1;;j++) { if(check(i,j)) { a[i]=j; break; } } } cin>>i; while(i!=0) { cout<<a[i]<<endl; cin>>i; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator