算法竞赛入门经典-第五章cantor数表

【信息科学与工程学】计算机科学与自动化——第三篇 计算理论基础05 计算数论01 车联网(IoV)算法是支撑智能交通系统高效、安全运行的核心技术,涵盖通信调度、路径规划、数据处理、决策控制等多个维度。 阅读详情
#include<stdio.h>
int main() {
  int n;
  while(scanf("%d", &n) == 1) {
    int k = 1, s = 0;
    for(;;) {
      s += k;
      if(s >= n) {
        printf("%d/%d\n", s-n+1, k-s+n);
        break;
      }
      k++;
    }
  }
  return 0;
}
//以上为方法一
#include<stdio.h>
#include<math.h>
int main() {
  int n;
  while(scanf("%d", &n) == 1) {
    int k = (int)floor((sqrt(8.0*n+1)-1)/2-1e-9)+1;
    int s = k*(k+1)/2;
    printf("%d/%d\n", s-n+1, k-s+n);
  }
  return 0;
}
//以上为方法二
//两种方法都用了数学知识来简化程序编写
//能不能用其他方法?比如说我感觉这个数据结构形式很像链表
//这个题...离了数学....似乎不能做....
//以下是一个比较程序一点的方法.....
//我发现我在把简单问题搞复杂上真是一把好手
产业园区如何高效对接企业技术需求与高校科研成果?.docx 科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

相关推荐

ESP32搭配FT6236触摸屏:从芯片手册到完整I2C驱动代码的保姆级解析

本文详细解析了ESP32搭配FT6236触摸屏的I2C驱动开发过程,从芯片手册解读到完整代码实现。通过硬件架构分析、寄存器配置、I2C通信封装及触摸数据处理等步骤,提供了一套完整的驱动解决方案,帮助开发者快速掌握ESP32与触摸屏的交互技术。

weixin_29174385的博客 294

Cantor数表

cantor数表(算法竞赛入门  p81)               1/1       1/2        1/3      1/4         1/5...............               2/1       2/2        2/3      2/4               3/1       3/2        3/3

-_-独行侠>_> 578

手把手教你用Arduino和开源电路DIY一个手机连接的电化学传感器(附GitHub源码)

本文详细介绍了如何利用Arduino和开源电路DIY一个手机连接的电化学传感器,成本不到300元即可复现价值数千元的专业设备。从硬件选型、电路搭建到固件开发和手机应用实现,手把手教你完成整个项目,特别适合科研人员、环境监测爱好者和理工科学生。附GitHub源码,方便快速上手和扩展功能。

weixin_42561040的博客 336

Cantor的数表

如下列数,第一项是1/1,第二项是1/2

思卟予 550

光通信仿真入门:手把手教你用VPI和Matlab搭建第一个联合仿真系统(含避坑指南)

本文详细介绍了如何使用VPI和Matlab搭建光通信联合仿真系统,涵盖软件配置、链路搭建、数据交互等关键环节,并提供常见问题的解决方案。特别适合初学者快速掌握光通信仿真技术,避免常见错误,提升仿真效率。

weixin_28733637的博客 378

AD4030-24BBCZ详细资料 Analog Devices 模数转换器 - ADC 24-Bit, 2 MSPS, SAR ADC

AD4030-24BBCZ详细资料  Analog Devices 模数转换器 - ADC 24-Bit, 2 MSPS, SAR ADC

Chen_YYan的博客 794

算法竞赛入门经典:第五章 基础题目选解 5.9 Cantor数

/* Cantor的数表: 如下列数,第一项是1/1,第二项是1/2,第三项是2/1,第四项是3/1,第五项是2/2,......。 输入n,输出第n项。 1/1 1/2 1/3 1/4 1/5 2/1 2/2 2/3 2/4 3/1 3/2 3/3 4/1 4/2 5/1 (本质上是一个折线) 输入: 3 14 7 12345 输出: 2/1 2/4 1/

qingyuanluofeng的专栏 587

S32DS S32K312 LPSPI + DMA配置异步SPI

配置DMA->Specific Configuration->Dma Logic Channel->Configuration->Global。SpiPhyUnitMapping:将该配置Mapping到某一路Spi,此工程配置为Spi1,遂选择LPSPI_1。配置的该路SPI的片选ID,此处ID对应配置Pin脚时lpspi_pcs后的下表(本工程此处为PCS3)配置该路SPI对应的SPI硬件单元ID,本工程配置为Lpspi1,因此配置为CSIB1。首先配置SPI的Pin脚,此处使用的是LPSPI_1。

希望我的博客,能帮上你解决学习中工作中所遇到的问题 2363

《算法竞赛入门经典》5.41数学基础-Cantor的数表

如下数列,第一项是1/1,第二项是1/2,第三项是2/1,第四项是3/1,第五项是2/2,……。输入n,输出第n项。1/1 1/2 1/3 1/4 1/52/1 2/2 2/3 2/43/1 3/2 3/34/1 4/25/1样例输入:314712345样例输出:2/12/41/459/99方法一: 1 #include <std...

aawyxv2369的博客 191

通过轻量级图像增强Transformer (IAT) 提升YOLOv8在低光环境下的检测性能

随着深度学习和计算机视觉的快速发展,目标检测模型在各个领域中的应用不断扩展,特别是在低照度环境下的视觉任务。YOLOv8作为当前最先进的目标检测模型之一,在高亮度和良好照明条件下表现出色,但在低照度环境下的性能存在一定的不足。为了解决这一问题,我们提出了一种轻量级的低照度图像增强网络(IAT)来改进YOLOv8的暗光检测能力。本篇文章将深入探讨这一创新改进,并附带代码实现,帮助大家更好地理解这一技术的应用和效果。

博客 1214

cesium 综合教程200+【目录】(已包含186篇文章)

cesium示例教程100+旨在为开发者提供简单快捷的,。在每一个示例中,解释相应的API知识点,做到。目录中有链接的为已有文章,没链接的为目标文章,不断更新中…

大剑师兰特的GIS世界 8893

算法竞赛入门——Cantor的数表

如下列数,第一项是1/1,第二项是1/2,第三项是2/1,第四项是3/1,第五项是2/2,……。输入n。输出第n项。 1/1 1/2 1/3 1/4 1/5 2/1 2/2 2/3 2/4 3/1 3/2 3/3 4/1 4/2 5/1输入样例: 3 14 7 12345 输出样例: 2/1 2/4 1/4 59/99 分析:本题可以看成对1~n进行求和代码如下:#include <iostream

just_do_it567的博客 505

基于TF-IDF+KMeans聚类算法构建中文文本分类模型(附案例实战)

TF-IDF(Term Frequency-Inverse Document Frequency, 词频-逆文件频率)是一种用于资讯检索与资讯探勘的常用加权技术。TF-IDF是一种统计方法,用以评估一字词对于一个文件集或一个语料库中的其中一份文件的重要程度。字词的重要性随着它在文件中出现的次数成正比增加,但同时会随着它在语料库中出现的频率成反比下降。简单来说就是:一个词语在一篇文章中出现次数越多, 同时在所有文档中出现次数越少, 越能够代表该文章。这也就是TF-IDF的含义。

m0_64336780的博客 1万+

算法竞赛入门经典 习题笔记

1.排序(permutation) 用1,2,3...9这9个数字组成3个三位数abc,def,ghi,每个数字恰好用一次,要求: abc:def:ghi = 1:2:3. 输出所有的解.提示:不必太动脑筋. 算法思想:确定满足比例关系的3个三位数是否是由9个不同的数组成.可以分离这3个三位数的每一位,用一个长度为>=9的数组标记.假设有数字122; 则数组s[1] = s[2] = 1;

大米粒ing 1513

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

cantor数表

/* 问题 A : 小俞同学的数表 时间限制:1 秒内存限制:128 兆特殊判题: 否 提交:44解决: 11 题目描述 小俞同学,最近勤学苦练数学,对一种数表产生了兴趣。 数表如下: 1/1 1/2 1/3 1/4 1/5 2/1 2/2 2/3 2/4 3/1 3/2 3/3 4/1 4/2 5/1 她冥思苦相了好久,貌似摸到了一点规律,但是她不知道自己的规律找的对不对,

听自己心跳的声音 714

深度学习工具包 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")

算法竞赛入门 5.4.1 Cantor的数表

重点: 1.按对角线第i行有i个元素,且当i为奇数时,

littlekenan的专栏 586

SAP B1中文培訓教材_SDK

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

UVA - 264 - Count on Cantor (Cantor的数表!)

UVA - 264 Count on Cantor Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  Count on Cantor 

Never say never 1284

算法竞赛入门经典 5.4.1Cantor数表

#include #include int main(){ int n; while (scanf("%d", &n) == 1){ int k = (int)floor((sqrt(1 + 8.0 * n) - 1) / 2 - 1e-9); int s = n - (1 + k) * k / 2; int numerator = k % 2 == 0 ? k + 2 - s

Ice He's Note 589

《算法竞赛入门经典》例题5.4.1

题目:现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的。他是用下面这一张表来证明这一命题的: 第一项是1/1,第二项是是1/2,第三项是2/1,第四项是3/1,第五项是2/2,……。输入n,输出第n项。 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … 3/1 3/2 3/3 … 4/1 4/2 … 5/1 … 样例输入:   3   14   7   12345   样例输出:   2/1   2/4   1/4   59/99 分析:   数表提示我们

guoyuxin3的博客 1053

算法竞赛入门经典-第五章源代码

// 程序5_1_1 WERTYU #include const char* s = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; //常量数组 int main(void) { int i, c; while((c=getchar()) != EOF){ for(i=1; s[i]&&s[i]!=c; i

侘寂 477

笔记——洛谷P1014Cantor表

笔记——洛谷P1014Cantor表 这道题有一个主要的坑点是z型排序是什么东西。所谓z字型排序,就是指对应一个正方形表格,以斜行为单位,依次遍历,其方向为从左上角开始,向右上,向左下,向右上,向左下(如图所示)。 值得一提的是:最左上角的(1,1)方格作为起点是没有方向的(它所在的斜行仅有它自己),我是为了方便理解才描述成向右上的。 依照上图描述的排序方式,每格的编号如下: 此外,考虑到题中给的cantor数表是三角形的,我们可以把图再裁剪掉一半,就是这样: 把这张“编号图”重叠在数表上就可以清晰的

qq_42959646的博客 396

UVa 264 - Count on Cantor

  《算法竞赛入门经典》5.4.1的题目,大意是,给出一个数表,如下:   第一项是1/1, 第二项是1/2, 第三项是2/1, 第四项是3/1, 第五项是2/2.....给一个正整数n,求第n项。   设第n个数在第k斜行,则有(k-1)*k/2 + 1 <= n <= k*(k+1) ==> (k-1)2<= k2 - k + 2 <=...

weixin_33730836的博客 105
上一篇: 算法竞赛入门经典-第五章字母重排
下一篇: 算法竞赛入门经典-第五章因子和阶乘
RachelF
博客等级 码龄10年 4粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值