高程: 输入数字n,n个人围成一圈,顺序排号,从第一个开始报数(从1到3报数),最后留下的是原来的第号?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高程: 输入数字n,n个人围成一圈,顺序排号,从第一个开始报数(从1到3报数),最后留下的是原来的第号?相关的知识,希望对你有一定的参考价值。

越简单越好

请楼主查收
m为人数,n为要报的数
int main()



int s=0,m,n,i;

scanf("%d %d",&m,&n);

for(i=2;i<=m;i++)

s=(s+n)%i;

printf("The left child is NO %d.\n",s+1);
return 0;

参考技术A 楼上回答是错的! 楼主的意思是到数的还得去除!约瑟夫问题! 数据结构上有 ! 结果就是那个还是1的那个
#include<iostream>
using namespace std;
void v(int *a,int gape,int n)

int k=0,count=0;
for(int j=0;j<n-1;j++)

while(true)

if(a[k]==1)

count++;

if(count==gape)

a[k]=0;
count=0;
break;

k++;
k=k%n;



int main()

int n,gape,*a,i;
cout<<"enter the number of people"<<endl;
cin>>n;
cout<<"enter the gape:"<<endl;
cin>>gape;
a=new int[n];
for(i=0;i<n;i++)

a[i]=1;

v(a,gape,n);
for(i=0;i<n;i++)

cout<<a[i];

delete[] a;
return 0;
参考技术B 请将题目补充完整

以上是关于高程: 输入数字n,n个人围成一圈,顺序排号,从第一个开始报数(从1到3报数),最后留下的是原来的第号?的主要内容,如果未能解决你的问题,请参考以下文章