| ||||||||||
| 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:90303121 at 2004-05-25 20:15:57 #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