Josephus problem
来源:互联网 发布:限制软件联网 编辑:程序博客网 时间:2024/05/17 23:49
#include <stdlib.h>
#include <stdio.h>
struct node{
int item;
struct node * next;
};
typedef struct node * link;
int main(int argc, char **argv)
{
if(!argv[1] || !argv[2])
{
printf("please input your two number\n");
return -1;
}
int N = atoi(argv[1]);
int M = atoi(argv[2]);
link x , t = (link)malloc(sizeof(struct node));
x = t;
t->item = 1;
t->next = t;
int i ;
link p = NULL;
for( i = 2; i <= N ; i++)
{
x->next = (link)malloc(sizeof(struct node));
x = x->next;
x->next = t;
x->item = i;
}
while(t->next != t)
{
for(i = 1 ; i < M; i++)
t = t->next;
printf("%d\n",t->next->item);
t->next = t->next->next;
}
printf("%d\n",t->item);
return 0;
}
#include <stdio.h>
struct node{
int item;
struct node * next;
};
typedef struct node * link;
int main(int argc, char **argv)
{
if(!argv[1] || !argv[2])
{
printf("please input your two number\n");
return -1;
}
int N = atoi(argv[1]);
int M = atoi(argv[2]);
link x , t = (link)malloc(sizeof(struct node));
x = t;
t->item = 1;
t->next = t;
int i ;
link p = NULL;
for( i = 2; i <= N ; i++)
{
x->next = (link)malloc(sizeof(struct node));
x = x->next;
x->next = t;
x->item = i;
}
while(t->next != t)
{
for(i = 1 ; i < M; i++)
t = t->next;
printf("%d\n",t->next->item);
t->next = t->next->next;
}
printf("%d\n",t->item);
return 0;
}
0 0
- Josephus problem
- josephus problem
- Josephus problem
- Josephus Problem
- Josephus Problem
- Josephus problem
- Josephus Problem
- The Josephus Problem
- The Josephus Problem
- 【算法实现】josephus problem
- 约瑟夫问题(Josephus problem)
- Josephus problem(约瑟夫问题)
- TOJ 10006 Josephus Problem
- Josephus problem solution
- CareerCup Josephus Problem
- LightOj 1179 Josephus Problem
- 约瑟夫问题Josephus problem
- Josephus problem(输出Josephus序列)
- 红外遥控NEC协议使用总结
- [微软编程之美挑战赛P2]女神---CLJ神犇的代码
- 大多数算法及其推广
- 自组网(Adhoc)和基础网(Infra)
- TRUSTAODV[转载]
- Josephus problem
- mysql学习--mysql必知必会1
- ODEX文件格式
- ios学习--多线程技术
- 在主函数内任意输入一个5X6矩阵,编写一函数求出每一行的和放到一个一维数组中,输出此矩阵及其每一行的和。
- zTree实现更新根节点中第i个节点的名称
- codeforces 432C Prime Swaps
- TCPIP的几个简易概念
- Android ELF文件格式