约瑟环问题(O(n)简单算法)多种算法

专题·约瑟夫问题集锦【including 约瑟夫问题,约瑟夫环,反约瑟夫问题,好人坏人…… 初见安~这里是约瑟夫专题 & 数论专题(5)~【详见数论专栏 不要小瞧约瑟夫哦~【预防针 //题目来自于某入门OJ 一、出队顺序 Description 有M个人,其编号分别为1-M。这M个人按顺序排成一个圈。现在给定一个数N,从第一个人开始依次报数,数到N的人出列,然后又从下一个人开始又从1开始依次报数,数到N的人又出列...如此循环,直到最后一个人出列为止。 Input ... 阅读详情
/*
Description




将m个孩子从1到m编上号,按序号围坐成一个圈,从1号孩子开始数,每数到n时,被数到的孩子即离开圈子,然后从下一个孩子开始,再从1开始数,如此不断地数下去,只到只剩下最后一个孩子,问剩下的孩子是几号?



Input




输入为一组整数对,每个整数对占一行,整数对的第一个整数表示m,即孩子的个数,第二个整数表示n,即被数到n的孩子将离开。

0<m<10000, n>0

输入以0 0作为结束。



Output




每组整数对输出一个结果整数,每个输出占一行。

最后一行输入0 0不产生输出。



Sample Input




8 3
5 2
0 0


Sample Output




7
3
*/


/*NO.1 (O(n) )算法*/


#include 
< stdio.h >
#include 
< math.h >

int  main( void )
{
    
int m,r;
    
int i , j, s=0;
    
    scanf(
"%d %d"
约瑟夫环O(N)和O(M*N)算法详解 约瑟夫环 O(n),O(n*m)算法。递推,动态规划。数组,循环链表。 阅读详情

相关推荐

[算法]约瑟夫环问题

约瑟夫环问题描述: 约瑟夫环问题(Josephus)       用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。写出C程序。(约瑟夫环问题 Josephus)

退而结网 1219

一步一步求解约瑟夫(Joseph)问题

详细介绍了用模拟法和公式法求解约瑟夫(Joseph)问题,并给出了相应的分析

w57w57w57的专栏 4857

四足机器人跨楼层轨迹规划:SCAN-Planner-Pure-ROS2开源项目实践指南

在机器人导航领域,路径规划是让机器人从起点安全、高效移动到目标点的核心技术。其原理通常基于环境地图(如占据栅格地图或八叉树地图),通过搜索算法(如A*、RRT*)在配置空间中找到一条无碰撞的可行路径。这项技术的价值在于赋予机器人在复杂、非结构化环境中的自主移动能力,是巡检、救援、物流等应用场景的基石。对于四足机器人而言,其运动能力超越了轮式平台,能在楼梯、斜坡等三维地形中移动,这使得传统的二维规划不再适用,需要专门的三维轨迹规划算法。SCAN-Planner-Pure-ROS2正是这样一个专注于解决四足机器

weixin_30700977的博客 462

nnU-Net v2实战:从零开始配置环境与训练自定义医学影像数据集

本文详细介绍了nnU-Net v2在医学影像分割中的实战应用,从环境配置到自定义数据集训练的全流程。重点讲解了Python 3.9+环境搭建、PyTorch安装技巧、医学影像数据预处理规范,以及五折交叉验证训练方法,帮助开发者快速掌握这一先进的医学影像分析工具。

weixin_28718487的博客 352

Spring Boot 构建war 部署到tomcat下无法在Nacos中注册服务

因此,当使用外部容器时,如此处的 Tomcat 来部署项目,AbstractAutoServiceRegistration 就不能监听到容器启动事件了,也就不会尝试向服务注册中心注册当前这个微服务,那么注册就失败了,并且也就没有异常信息了。自定义获取获取外部容器端口的方法, 然后监听应用启动事件,当应用被启动时,获取外部容器启动的端口号,然后将这个 port 设置到 NacosAutoServiceReigistration 中。在启动类同级目录,复制下面代码即可(不需要修改,直接构建war即可)

ttyy1112的专栏 2519

Syzkaller实战教程2:运行环境配置+实例运行

本文详细介绍了在linux系统上搭建Syzkaller内核模糊测试环境的完整流程。 1.环境配置:通过VMware创建Ubuntu20.04虚拟机A,配置QEMU/KVM虚拟化环境,安装Go语言工具链和Syzkaller; 2.内核编译:下载Linux内核源码并配置KCOV等调试选项,编译生成带覆盖率支持的bzImage内核镜像; 3.测试环境构建:使用debootstrap创建Debian虚拟机镜像,通过QEMU启动嵌套虚拟机B; 实例测试: 4.演示两种测试场景 - 提供完整上手教程

cuguanren的博客 1375

2、欧洲期权的赫斯顿模型

本文详细介绍了赫斯顿随机波动率模型在欧洲期权定价中的应用。模型通过引入随机方差过程,克服了布莱克-斯科尔斯模型中波动率恒定的局限性,更贴近市场实际。文章阐述了模型的动态结构、风险中性转换、期权定价公式及其半封闭解的计算方法,并提供了基于VBA的数值实现方案。通过梯形法则与高斯积分等数值方法对比,分析了不同积分策略的精度与效率。同时验证了当波动率为零时,赫斯顿模型退化为布莱克-斯科尔斯模型的一致性。最后讨论了模型的优势、挑战及实际应用建议,强调了数值积分稳定性和参数估计的重要性。

tequila的博客 348

工具变量法入门:解决因果分析中的内生性问题

想知道如何在复杂的数据中精确揭示因果关系?你是否遇到过自变量与误差项相关导致的困惑?工具变量法将为你拨开迷雾,帮助你剖析数据背后的因果链条。这篇文章不仅详细讲解了工具变量法的原理,还结合实际案例,让你轻松掌握这一关键研究工具。点击阅读,开启你的因果分析新篇章!

theskylife的博客 1953

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

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

点云侠的博客 628

Spring AI 项目实战(五):Spring Boot + AI + DeepSeek + Redis 实现聊天应用上下文记忆功能(附完整源码)

本文介绍了如何基于Spring Boot 3.2、Spring AI 1.0.0-M4、DeepSeek API和Redis构建具备上下文记忆功能的智能聊天应用。项目采用现代化技术栈,包括Java 17、Maven、Lombok等,实现了智能对话、会话管理、异常处理等核心功能。文章详细讲解了环境搭建、配置管理(含Redis和AI服务集成)、核心组件设计(如消息实体、控制器和服务层实现),以及完整的项目结构。该项目提供了美观的Web界面和REST API,支持对话上下文存储(通过Redis实现)和系统监控,可

博客 829

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: 内存控制函数全集 Linux C
下一篇: 内存操作函数全集 Linux C
oopos
博客等级 码龄19年 21粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值