据说着名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人 开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀身亡为止。 然而Josephus 和他的朋友并不
public class Main { public static void main(String[] args) { int list[] = new int[41]; for (int i = 0; i < 41; i++) { list[i] = (i + 1); } int i = 0, num = 41, flag = 0; while (num > 2) { //有效数字 if (list[i]!=0) { flag++; if (flag == 3) {...
b.append(i)# print(i, end=' ') # print the order of removingifa.index(i) ==len(a)-1:# last man of sequenceend = (end+a.index(i)+1)%m# remove elements in b from aforiinb: a.remove(i)returna[0]# solve the problem by math methoddefsolve2(N, m):return0ifN ==1else(s...
约瑟夫环(Josephus Problem),又称为约瑟夫斯置换,是一个在计算机科学和数学中广泛讨论的问题 其起源于一个历史故事 约瑟夫环约瑟夫环(Josephus Problem),又称为约瑟夫斯置换,是一个在计算机科学和数学中广泛讨论的问题。其起源于一个历史故事:在罗马人占领乔塔帕特后,约瑟夫和他的朋友与39个犹太人躲到一个洞中,他们...
Josephus Problem Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. Original ID:1179 64-bit integer IO format: %lld Java class name: Main Prev SubmitStatusStatisticsDiscuss Next None • None • Graph Theory ...
The problem is named after Flavius Josephus, a Jewish historian who participated in and chronicled the Jewish revolt of 66-70C.E. against the Romans. Josephus, as a general, managed to hold the fortress of Jotapata for 47days, but after the fall of the city he took refuge with 40 dieha...
java实现约瑟夫环问题Josephus 约瑟夫问题 * 已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围。从编号为k(1,2,3...n)的人开始报数,数到m(1,2,3...)的那个人出列; * 他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,直到圆桌周围的人全部出列。求出圈顺序 ...
Description: This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. Refusing to surrender to the enemy, they instead opted for mass ...
1/***2*3* Josephus problem4*5* % java Ex_1_3_37 7 26* 1 3 5 0 4 2 67*8***/910publicclassEx_1_3_3711{12publicstaticvoidmain(String[] args)13{14intn = Integer.parseInt(args[0]),15m = Integer.parseInt(args[1]);1617Queue<Integer>...