约瑟夫环问题
来源:互联网 发布:如何运行php文件 编辑:程序博客网 时间:2024/06/07 11:38
int joseph(int a[],int n,int m)
{
for(int i = 0;i<n;i++)
a[i] = 1;
int sum = n;
int start = 0;
int count = 0;
while(sum>=2)
{
count = 0;
while(count !=m)
{
if(a[start]!=0)
{
count++;
if(count == m)
break;
}
start = (start + 1)%n;
}
a[start] = 0;
sum--;
cout<<"the content of the array:"<<endl;
for(int t = 0;t<n;t++)
cout<<a[t]<<"\t";
cout<<endl;
}
for(int j = 0;j<n;j++)
if(a[j]!=0)
{
return j+1;
}
}
{
for(int i = 0;i<n;i++)
a[i] = 1;
int sum = n;
int start = 0;
int count = 0;
while(sum>=2)
{
count = 0;
while(count !=m)
{
if(a[start]!=0)
{
count++;
if(count == m)
break;
}
start = (start + 1)%n;
}
a[start] = 0;
sum--;
cout<<"the content of the array:"<<endl;
for(int t = 0;t<n;t++)
cout<<a[t]<<"\t";
cout<<endl;
}
for(int j = 0;j<n;j++)
if(a[j]!=0)
{
return j+1;
}
}
阅读全文
0 0
- 约瑟夫问题、约瑟夫环
- Josephus约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题(Josephus)
- 约瑟夫环问题--java
- 约瑟夫环问题 Josephus
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 求解约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- 约瑟夫环问题
- onload事件
- 【面试题】剑指offer26--复杂链表的复制
- 网络编程(Socket编程)
- 【python代码技巧1】文件查找&数组变维
- 我爱她她也爱我这才是真正恋情
- 约瑟夫环问题
- idea 破解
- Java Web基础知识之Servlet
- 1260: 找子串
- SpringBoot简介
- Socket网络程序设计(2) ———— 基于UDP协议的客户-服务器socket实例
- jQuery发送Ajax请求
- 剑指offer——栈的压入,弹出序列
- 直接插入排序