问题补充说明:狼找兔子问题:一座山周围有n个洞,顺时针编号为0,1,2,3,4,…,n-1。一只狼从0号洞开始,顺时针计数,每当经过第m个洞时,就进洞找兔子。例如n=5,m=3,狼经过的洞依次为0,3,1,4,2,0.输入m,n。试问兔子有没有幸免的机会?如果有该藏在哪儿?
#include<iostream>
usingn说染成将告王每工还amespacestd;
intmain()
{
intn,m,i,c;
intj=0,k=0;
inta[50],b[50];
cout<<"请输入山周围的洞口总数:";
cin>>n;
cout<<endl<<"请输入狼每次经过洞口的个数:";
cin>>m;
cout<<endl<<"洞包若细品联然极二香绿新口号码依次为:";
for(i=0;i<n;i++)
{
a[i]=i;
cout<<a[i]<<"";
}
cout<<endl<<endl<<"狼依次经过植曾营首态汽另的洞口号码为:0";
while(c!=0)
{
k+=m;
c=k%n;
b后龙族[c]=c;
j++;
cout<<b[c]<<"";
配定}
if(j==n)
cout<<endl<<endl<<"兔子没有幸免的机会"<<endl;
else
{
cout<<endl<<endl<<"兔子有幸免的机会"<<en田画陆室非场银下dl;
for(i=0;i<n;i++)
if(b[i]!=a[i])
cout<<endl<<"兔子可以藏在"<<i<<"洞口中"<<endl;
}
return0;
}
标签:C++,兔子,来自