练习题 3.10 -- Josephus问题

Josephus问题 C++实现 要求 Josephus问题,n个人围坐成一圈,按顺序编号为1-n,确定一个整数m,从1号开始数数,每数到第m个人出列,剩下的人从下一个人重新开始数,直至只剩下一个人为止。对n=8,m=5,过程和结果如下图所示,黑色数字为编号,红色数字为出列顺序,最后剩下的是3号 编写程序,对任意输入的n和m,求出最后剩下的人的编号。要求利用线性表保存这n个人,分别用公式化和链表两种描述方法实现。 输入... 阅读详情

这是一个Josephus问题
http://en.wikipedia.org/wiki/Josephus_problem上面有如下的说法。
There are n people standing in a circle waiting to be executed. After the first man is executed, k − 1 people are skipped and the k-th man is executed. Then again, k − 1 people are skipped and the k-th man is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last man remains, who is given freedom.
The task is to choose the place in the initial circle so that you survive (are the last one remaining), given n and k.

翻成中文
http://zh.wikipedia.org/wiki/%E7%BA%A6%E7%91%9F%E5%A4%AB%E6%96%AF%E9%97%AE%E9%A2%98
有n个囚犯站成一个圆圈,准备处决。首先从一个人开始,越过k − 2个人,并杀掉第k个人。接着,再越过k − 1个人,并杀掉第k个人。这个过程沿着圆圈一直进行,直到最终只剩下一个人留下,这个人就可以继续活着。
问题是,给定了n和k,一开始要站在什么地方才能避免被处决?

对于k=2的情况,有下面这样的定理,具体的证明过程,参考wiki
定理: 如果n = 2m + l 且0/leq l<2^m ,则f (n ) = 2l + 1 。

我用很笨拙的链表实现的一个

  1. void  josephuse(list **p,  int  n,  int  k)
  2. {
  3.     list    *before, *next, *cur;
  4.      int      counter;
  5.     assert(NULL != p);
  6.     assert(NULL != *p);
  7.     before = cur = *p;
  8.     k = k % n;
  9.     counter = 0;
  10.      while (cur) {
  11.         counter++;
  12.          if ( counter == k) {
  13.             n--;
  14.             counter = 0;
  15.             printf( "deleting pos %d/n" , cur->pos);
  16.             before->next = cur->next;
  17.             free(cur);
  18.             cur = before->next;
  19.              if ( 1 == n)  break ;
  20.              continue ;
  21.         }
  22.         before = cur;
  23.         cur = cur->next;
  24.     }
  25.     printf( "last pos is %d/n" , before->pos);
  26. }

全部的的程序

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. typedef   struct  list_t list;
  6. struct  list_t {
  7.      int      pos;
  8.     list*   next;
  9. };
  10. void  josephuse(list **p,  int  n,  int  k)
  11. {
  12.     list    *before, *next, *cur;
  13.      int      counter;
  14.     assert(NULL != p);
  15.     assert(NULL != *p);
  16.     before = cur = *p;
  17.     k = k % n;
  18.     counter = 0;
  19.      while (cur) {
  20.         counter++;
  21.          if ( counter == k) {
  22.             n--;
  23.             counter = 0;
  24.             printf( "deleting pos %d/n" , cur->pos);
  25.             before->next = cur->next;
  26.             free(cur);
  27.             cur = before->next;
  28.              if ( 1 == n)  break ;
  29.              continue ;
  30.         }
  31.         before = cur;
  32.         cur = cur->next;
  33.     }
  34.     printf( "last pos is %d/n" , before->pos);
  35. }
  36. #define LEN     1000
  37. #define KTH     2
  38. int  main( void ) 
  39. {
  40.      int      i;
  41.     list    *p,*tmp, *last;
  42.      /* malloc head */
  43.     p = (list*)malloc( sizeof (list));
  44.      if (!p)  return  -1;
  45.     p->pos = 0;
  46.     p->next = NULL;
  47.     last = p;
  48.      /* alloc 9 more */
  49.      for (i = 1; i < LEN; i++) {
  50.         tmp = (list*)malloc( sizeof (list));
  51.          /* take care the memory allocated are not freed by hand */
  52.          if (!tmp)  return  -1;
  53.         last->next = tmp;
  54.         tmp->pos = i;
  55.         tmp->next = NULL;
  56.         last = tmp;
  57.     }
  58.     last->next = p;
  59.     josephuse(&p, LEN, KTH);
  60.      return  EXIT_SUCCESS;
  61. }

验证
N     K     last
10    2     5 - 1   
1000  2     977 - 1
1000  3     604 - 1

找到了网上更好的算法如下2009/6/2

 

数据结构实验2.3:Josephus问题求解 在这个循环单链表中,每个结点都应该包含三个重要成员:一个用于记录该结点对应人的序号(方便识别是哪个人),一个用于存储该人持有的密码(影响后续报数的 m 值),还有一个指针成员,用于指向下一个结点,从而将所有结点连接成一个环形结构。该算法要能够按照问题描述的规则,从初始的 m 值开始,通过报数、出圈、更新 m 值等一系列操作,最终实现所有人的出列,并输出相应的出圈顺序。随着循环的进行,链表中的结点逐渐减少,直到链表为空,即所有人都已经出圈,此时整个 Josephus 问题的求解过程结束。 阅读详情

相关推荐

约瑟夫(Josephus)环问题:编号为1,2,3,…,n的n个人按顺时针方向围坐一圈,每人持有一个密码(正整数)

约瑟夫环2、 约瑟夫(Josephus)环问题:编号为1,2,3,…,n的n个人按顺时针方向围坐一圈,每人持有一个密码(正整数)。一开始任选一个正整数作为报数的上限值m,从第一个人开始按顺时针方向自1开始顺序报数,报到m时停止。报m的人出列,将他的密码作为新的m值,从他在顺时针方向上的下一人开始重新从1报数,如此下去,直到所有人全部出列为止。 建立n个人的单循环链表存储结构,运行结束后,输出依次出队的人的序号。

约瑟夫环问题 Python3实现

Python学习笔记 尝试用Python3实现约瑟夫环问题。 约瑟夫环问题的描述: 约瑟夫斯问题(有时也称为约瑟夫斯置换),是一个出现在计算机科学和数学中的问题。在计算机编程的算法中,类似问题又称为约瑟夫环。 有 n个囚犯站成一个圆圈,准备处决。首先从一个人开始,越过  k-2个人(因为第一个人已经被越过),并杀掉第k个人。接着,再越过 k-1个人,并杀掉第k个人。这个过程沿着圆圈一直进行,...

huaxin820518的博客 7059

用c语言实现josephus环问题

#include <stdio.h> #include <malloc.h> #define NULL 0 #include <iostream.h> typedef struct Lnode{ int data; struct Lnode *next; }joseph;

Josephus问题(Ⅲ)

题目描述 n个人排成一圈,按顺时针方向依次编号1,2,3…n。从编号为1的人开始顺时针"一二三...."报数,报到m的人退出圈子。这样不断循环下去,圈子里的人将不断减少。最终一定会剩下一个人。试问最后剩下的人的编号。 本题的数据规模更具有挑战性,尝试更通用且高效的算法。 输入 不超过1000组数据。 每组数据一行,每行两个正整数,代表人数n (1 <= n < 231)和m(1<=m<=1000)。 输出 每组输入数据输出一行, 仅包含一个整数,代表最后剩下的人的.

weixin_50362597的博客 2877

(C++)Josephus问题---链式存储结构

用链式存储结构实现Josephus问题,用户按照执行提示输入n、s、m,输出题目要求的出列顺序

FDTD脚本教程——结构的创建

文章目录结构的搭建创建长方体创建柱体多边形柱体(椭)圆柱体圆环柱自定义形状创建surface波导球棱锥 在lumerical中,可以使用脚本进行操作,可在右侧脚本编辑器运行,或者直接在下方shell输入。 结构的搭建 创建长方体 um = 1e-6; nm = 1e-7; addrect; set("name","myRect"); set("material","SiO2 (Glass) - Palik"); set("render type","wireframe"); # 默认是细节渲染,也就是det

战斗果冻的训练中心 2万+

【算法专题】约瑟夫问题

约瑟夫问题 这个问题是以弗拉维奥·约瑟夫命名的,他是1世纪的一名犹太历史学家。他在自己的日记中写道,他和他的40个战友被罗马军队包围在洞中。他们讨论是自杀还是被俘,最终决定自杀,并以抽签的方式决定谁杀掉谁。约瑟夫斯和另外一个人是最后两个留下的人。约瑟夫斯说服了那个人,他们将向罗马军队投降,不再自杀。约瑟夫斯把他的存活归因于运气或天意,他不知道是哪一个。 —— 【约瑟夫问题】维基百科 本文会探讨约瑟夫问题的各种解法。 参考网址:剑指 Offer 62 题解、约瑟夫环、今日头条2018春招研发岗笔试 一

weixin_42638946的博客 841

宇树G1开发实践--PPT汇报(遥控版)

本文介绍了一种基于遥控器交互的机器人演示控制系统。系统通过DDS中间件接收遥控器信号,采用位掩码边沿检测技术实现按键精准响应,将不同按键映射为播放控制命令(暂停/重播、跳转、跳过等)。核心交互逻辑包含主播放循环、命令处理和暂停机制,支持播放过程中的实时控制。与自动顺序播放版相比,该系统显著提升了演示灵活性,适用于需要人机互动的演讲场景。使用前需确保网络连接和设备安全,并熟悉按键功能映射。该系统实现了专业级的人机协同演示体验。

m0_47999117的博客 682

josephus问题

看书上写的很蛋疼,好好的一个问题,不描述清楚,你妹程序怎么写!!!  josephus问题:Josephus问题:设有n个人围坐在一个圆桌周围,现从第s个人开始报数,数到第m的人出列,    然后从出列的下一个人重新开始报数,数到第m的人又出列……如此反复直到所有的人全部    出列为止。Josephus问题是:对于任意给定的n,s,m,求出按出列次序得到的n个人员的序列。 #in

wangzhiqing3的专栏 1370

PCL 加权局部最优投影(WLOP)简化算法

WLOP算法是一种点云重采样方法,通过迭代优化实现点云均匀化和特征保留。算法包含数据项(加权平均位置保持几何特征)和正则化项(排斥邻近点实现均匀分布)两部分。代码实现基于PCL库,通过KD树加速邻域搜索,使用高斯权重函数计算点位置更新。参数包括输出点比例、邻域半径、正则化权重和迭代次数。该算法不依赖网格信息,适合处理大规模扫描数据的预处理优化。

点云侠的博客 648

【SpringBoot笔记44】SpringBoot多数据源配置(方式一:配置多个mapper扫描不同的包路径实现多数据源配置)

在SpringBoot应用开发中,一般情况下,都是只会配置一个数据源信息,之后整个工程都是对当前数据源进行增删改查的操作。但是,在实际开发里面,也有可能会遇到多数据源的情况,例如:当前工程中除了需要访问自己应用的数据库,还需要直接连接第三方系统的数据库进行业务处理,这种情况下,就需要进行多数据源的配置。SpringBoot考虑到了这一点,所以它是支持多数据源的配置的,下面介绍一下如何配置多数据源。

✅ Java 开发工程师 1120

“约瑟夫环”问题的四种方法及详解注释(c++实现)

Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀身亡为止。首先从一个人开始,越过k-2个人(因为第一个人已经被越过),并杀掉第。Josephus要他的朋友先假装遵从,他将朋友与自己安排在第16个与第31个位置,于是逃过了这场死亡游戏。接着,再越过k-1个人,并杀掉第。

2301_79227549的博客 8390

YOLO11 改进、魔改|分组残差自注意力GRSA,通过分组残差优化 QKV 计算、指数空间映射优化位置偏差,在大幅降低自注意力模块参数和计算量的同时,增强特征关系与位置信息的表征能力

【摘要】研究人员提出GRSA(分组残差自注意力)机制,解决Transformer在图像超分辨率任务中效率与性能难以兼顾的问题。GRSA通过分组残差层减少自注意力参数冗余,同时采用指数空间相对位置偏差优化位置信息表征。实验表明,GRSA在降低50%参数量的同时保持模型性能,适用于目标检测和图像分割任务。在YOLO系列模型中集成GRSA可提升小目标检测精度,代码实现已开源,详细部署教程见相关视频与GitHub资源。该机制为轻量化Transformer模型提供了高效解决方案。

qq_64693987的博客 809

Josephus问题之Java乱弹篇(原创)

Josephus问题之Java乱弹篇女儿生病住了几天医院,在我为女儿担心的同时也使我深深的感受到医疗产业化的伟大之处,在它一切向钱看的伟大精神指导之下,医生的工作积极性有了空前的提高,“开放思想,积极创收”成为各个医院的热门话题。我想大家也都发现了这种情况,那就是“没病当成有病看的多了,小病当成大病看的多了,大病当成重病看的多了”。为了让大家能看的起病,医疗产业化是不是到了该让它离开,还医院一

lxgljj的专栏 4208

MIKE 21 教程 2.9 初始条件(Initial Conditions),边界条件Boundary Conditions),解耦(Decoupling)

本节讲解初始条件与边界条件的设置。这两个模块如设置有误则极易出现模型崩溃。

Hello Word 4812

基于情感分析+聚类分析+LDA主题分析对服装产品类的消费者评论分析

本研究旨在通过对服装产品类的消费者评论进行综合分析,为企业提供更全面、更深入的市场洞察和决策支持。同时,本研究的方法和结果也可以为其他领域的消费者评论分析提供借鉴和参考。

m0_64336780的博客 2万+

算法(一):Josephus问题

Josephus是一个著名的犹太历史学家,他有过这样的故事(来自互动百科,http://www.baike.com/wiki/Josephus):在罗马人占领乔塔帕特后,39个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3个人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀

宁静致远 5606

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

链表应用:Josephus问题

今天学习了链表,找了一道经典的

学习笔记 1466

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Python求解Josephus问题

问题描述:n个人围成一圈,从第k个人开始报数,报道第m个数的人退出。然后从下一个人开始继续报数,按同样规则退出,直到所有人退出。 这道题目在C语言的数据结构教程里,基本都是拿循环单链表做的。在Python中,也可以定义循环单链表解决,但是还有更简单的方法。参考裘宗燕老师的数据结构教程的方法。 def josephus_L(n, k, m): people = list(range(...

SCUT_AUTO143的博客 768

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Java:实现Josephus问题算法(附带源码)

Java:实现Josephus问题算法(附带源码)

欢迎来到我的博客!这里是一个专注于计算机技术的分享平台,涵盖编程开发、算法研究、系统架构、软件工程等多个领域。无论你是初学者还是资深开发者,都能在这里找到有价值的内容。 1377

问题 D: Josephus问题(Ⅱ)

2024.6 hnust 23级 数据结构 课程设计 第四题 Josephus问题(Ⅱ)

weixin_50950742的博客 858

趣味算法(一)Josephus问题

Josephus问题求解:     设有n个人围坐一个圆桌周围,,现从第S人开始报数,数到第m的人出列,     然后从出列的下一个重新开始报数,数列的第m个人又出列……如此重复,直    到所有的人全部出列为止。对任意给定的n、s、m,求按出列次序得到的n个    人员的顺序表。   分析:对于n个人,每一次出列一个人,余下的n-1个人仍然是一个Josephus问题,因此可以使用递归的方...

lilywangcn 578

Josephus问题

    算法不是一般的烂呀,这个Josephus问题还纠结了半天。还好最后纠结出来了,其实很简单呀,弄个循环链表,遇到需要出列的就把这个节点从链表中删除,直到最后循环链表中只有一个节点。 1  void Josephus( ) 2  {

strongxu的专栏 2217

[PTA]约瑟夫环(Josephus)问题

约瑟夫环

weixin_52192405的博客 3995
上一篇: 练习题 3.12
下一篇: 练习 3.16 删除一组数据中的相同数据
magicpang
博客等级 码龄21年 11粉丝 39原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值