二分查找——UVa 10706 - Number Sequence

【01】VisionMaster入门到精通——VisionMaster V4.0.0 试用版安装教程(安装试用补丁与试用授权) 本文详细介绍了海康VisionMaster 4.0.0试用版的安装步骤:首先从官网下载基础安装包、软加密试用版和示例程序(可选);安装时需按顺序完成主程序安装(选择软加密)、试用补丁安装和30天试用授权安装;最后提供了两种启动方式。文章还列出了试用版的7项功能限制,包括最多支持2个流程、2个全局相机等,并特别提醒试用版不维护、不提供补丁,建议用户转为正式版本。安装过程中若出现蓝屏需重启覆盖安装,授权失败时可参考指定解决方案。 阅读详情

思路:

要得到给定位置的数字,只需要知道该位置处在的序列Sk和距离Sk首位的偏移量即可。

设seqLen[k]表示:S1S2…Sk的总长度,对于给定的i,用二分查找确定所在的Sk, i-Sk-1就是偏移量。

/*
Sk的长度:
k的范围
[1  , 9  ]: k
[10 , 99 ]: 9 + (k-9)*2
[100, 999]: 9 + 90*2 + (k-99)*3
...
*/

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

#define MAXN 31270
#define MAXLEN 146000

unsigned int seqLen[MAXN];

void InitSequenceLength(void)
{
	seqLen[0] = 0;
	unsigned int delta = 1, c = 10, sum = 0;

	int i;
	for (i = 1; seqLen[i-1] <= 2147483647; i++)
	{
		//当i为10、100、1000...时,delta需要加1
		if (i == c)
		{
			delta++;
			c *= 10;
		}
		sum += delta;
		seqLen[i] = seqLen[i-1] + sum;
	}
}

int BSearch(int low, int high, unsigned int targ)
{
	while (low <= high)
	{
		int mid = (low + high) / 2;

		if (targ == seqLen[mid])
		{
			return seqLen[mid-1];
		}
		else if (targ < seqLen[mid])
		{
			high = mid - 1;
		}
		else
		{
			low = mid + 1;
		}
	}
	return seqLen[high];
}

int main(void)
{
	InitSequenceLength();
	string maxSeq;
	maxSeq.reserve(MAXLEN+10);
	int i;
	for (i = 1; maxSeq.length() < MAXLEN; i++)
	{
		char temp[10];
		sprintf(temp, "%d", i);
		maxSeq += temp;
	}

	int ncases;
	scanf("%d", &ncases);

	while (ncases-- != 0)
	{
		unsigned int p;
		scanf("%d", &p);
		int i = BSearch(1, 31268, p);
		printf("%c\n", maxSeq[p-i-1]);
	}
	return 0;
}


Stata森林图进阶:个性化定制与高级技巧 本文详细介绍了Stata森林图的进阶技巧,包括个性化定制与高级应用。通过meta分析工具如metan命令,用户可以优化字体、颜色、坐标轴等视觉元素,提升森林图的专业性和可读性。文章还提供了黑白印刷设置、高分辨率导出等实用技巧,帮助科研人员制作符合学术出版要求的森林图。 阅读详情

相关推荐

Windows 环境下 OpenClaw 的安装与千问大模型配置

为了不占用 C 盘空间,重装系统也不丢失配置,本文详细记录了如何将 OpenClaw 安装在非系统盘,比如D 盘,并对接阿里云 通义千问大模型的全过程。主要是利用 NVM 和 npm 进行安装,方便后续一键升级,配置具有免费额度的Qwen API,这个只需要在阿里云百炼注册一个账号就能获得免费额度。

博客 6537

UVA - 10706 Number Sequence

先找到是在哪个集合内,再找到是集合内的哪个元素,最后找到元素的第几位数 #include #include #include #include using namespace std; long long table[100010]; long long psum[100010]; int n=100000; void maketable() { int i,flag=1,x=0;

Last Order 1272

港口集装箱码头运营FlexSim仿真

列队4中的集装箱会根据不同类型的集装箱会放置在不同的堆场,因此根据前面对集装箱设置的标签Type的数值不同,设置不同的发送端口。集装箱到达列队3后,会有70%的集装箱到达堆场,30%的集装箱运出港口,因此在Queue列队3的Flow界面设置按照百分比发送端口,其中70%发送到端口1,即发送到列队4等待进入堆场,30%发送到端口2,即发送至出闸口。通过上述对比表格可以看出,当集卡数量在10的时候,岸桥和场桥的设备利用率达到了最高,当集卡数量为12的时候场桥1和场桥3的利用率有所下降,因此综合考虑。

m0_72514516的博客 1331

【ICPC-162】uva 10706 - Number Sequence

点击打开链接uva 10706 题目意思: 有一个数组 s[1] = 1 , s[2] = 1 2 , .......s[k] = 1....k,要求给定一个n表示数组的第几位,要求这个第几位是什么数。例如 n为1 时候是1 n为 2 时候是1 ,n 为3 时候为2 解题思路: 1:思路:预处理打表+查找 2:题目给的数据可以发...

藏经阁 | 玄苦 2623

大麦APP抢票协议分析:从‘掌密网络’代码看移动端API安全防护

本文深度解析了大麦APP抢票协议的安全防护体系,重点分析了'掌密网络'代码中体现的动态签名、设备指纹和人机验证等关键技术。文章详细介绍了大麦APP如何通过多层次API安全防护应对抢票压力,包括参数加密、请求头部设计和异常处理机制,为移动应用开发者提供了安全实践建议。

weixin_28740299的博客 289

微信小程序、H5微信公众号网页JSAPI:解决报错requestMerchantTransfer:fail:internal error(使用wx.requestMerchantTransfer错误)

如何解决requestMerchantTransfer:fail:internal error,微信小程序wx.requestMerchantTransfer报错,微信公众号H5网页使用jssdk调用wx.requestMerchantTransfer报错,JSAPI调起用户确认收款报错errMsg:“requestMerchantTransfer:fail:internal error“,微信小程序/H5 调起确认收款界面,JSAPI调起用户确认收款,微信公众号(H5),用户发起提现,商家转账给用户,用户

✅ 精选推荐文章 4963

uva 10706 Number Sequence

// // main.cpp // uva 10706 - Number Sequence // // Created by XD on 15/8/20. // Copyright (c) 2015年 XD. All rights reserved. // //此题就是二分查找的应用 ,找到当前的n应该在哪个数的序列上,然后二分查找找到在这个数的哪个位置 二次二分查找就解决了问题 #in

最爱她! 472

CesiumForUnreal实现鹰眼地图(MiniMap)效果

CesiumForUnreal实现鹰眼地图(MiniMap)效果

专注GIS开发 3951

UVa 10706 - Number Sequence

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1647   题目大意: 定义了一种字符串s[k],表示数字1到数字k连接在一起,比如s[3]="123" 现在将字符串s[k]连接在一起,这样就能构成一个更长更复杂的字符串: 1121

sanmingzi3344的专栏 697

LLaMA Factory多卡微调的实战教程(持续更新)

本文主要介绍了LLaMA Factory多卡微调的实战教程(持续更新),希望对学习大语言模型的同学们有所帮助。 文章目录 1. 前言 2. 配置环境 2.1 安装虚拟环境 2.2 安装依赖库 2.3 模型选型与下载 2.4 配置多卡环境 3. 运行代码 3.1 构建训练数据 3.2 修改配置文件 3.3 微调 3.3.1 zero3微调 3.3.2 启动API 3.3.3 模型测试

herosunly的博客 25万+

ARM CoreLink 系列 5.1.1 -- CI-700 System Address Map 】

所有的CHI 命令都包含一个 Source ID 和 Target ID, 其中 Source ID 可以来自于 RN Node, Target ID 可以来自于HN node或者其他 SN node. 其中 Target ID 是通过 SAM解析传入的地址得到的。对于 CI-700中的所有 RN Node 中的 SAM 多会进行配置,因为RN Node 访问的是整个地址空间,不同的地址空间会有不同的属性(I/O, DRAM),所以会对RN SAM 配置多个不同属性的区域。

CodingCos的博客 771

UVa 10706 - Number Sequence

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1647 原题: A single positive integer i is given. Write a program to find the di

D_Double's Journey 1413

YOLOv8 智能交通违章检测 - 压线/越线行驶检测详解

本文提出了一种基于YOLOv8的智能交通违章检测方案,重点解决车辆压线/越线行驶的识别问题。系统采用多技术融合方案:YOLOv8检测车辆、ByteTrack跟踪轨迹、传统或深度学习方法识别车道线,并通过几何计算判断车辆是否违规跨越实线。文章详细介绍了技术难点(如车道线分类、透视变形处理)、判定流程、系统架构和核心代码实现,包括车道线检测、违章逻辑判断和可视化模块。同时指出了现有方案的局限性,建议通过引入逆透视变换和专用车道线分割模型来提升准确率。该纯视觉方案具有低成本、易部署的特点,适用于智能交通监控场景。

u010117029的博客 173

uva 10706 Number Sequence(找规律)

uva 10706 Number Sequence A single positive integer iis given. Write a program to find the digit located in the position iin the sequence of number groups S1S2…Sk. Each group Skconsists o

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 917

Camera2Demo

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

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

UVa 10706 Number Sequence

/* 思路: 二分法求出k值, 再对sk二分法求出所在数值, 最后确定所在位 */ #include #include #include using namespace std; int s1[] = {0, 45, 9045, 1395495, 189414495}; // 前0项 前9项 前99项 前999项 前9999项位数和 int s2[] = {0, 9, 189, 2889,

cugfjp的专栏 532

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

uva 10706 Number Sequence(数学规律)

题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1   1 2    1 2 3   1 2 3 4   1 2 3 4 5 。。。。就是第一位为1. 第二为为1 ,第三为为2, 然后10 的部分注意下, 为1  和0 两个, 100 就是1 , 0和0 三位,以此类推, 要求给出tmp, 输出序列中的tmp位为什么数字。 解题

不慌不忙、不急不躁 1261

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

uva10706 - Number Sequence(找规律)

题目:uva10706 - Number Sequence(找规律) 题目大意:有这样一串序列11212312341234512345612345671234567812345678912345678910123456789101112345678910...,问第i个位置数的值。                                                   1

1207

UVA 10706 Number Sequence

传送门:https://vjudge.net/problem/UVA-10706 题意:   112123123412345123456123456712345678……一直排下去问第i(i<2147483647)个数字是什么。 题解:   开始学二分的时候没做出来,最近练习二分的时候想起来了。。。。。   我们可以先打个表看看2147483647大致在什么地方,发现其实它是小于1...

weixin_30355437的博客 127

uva 10706 - Number Sequence

点击打开链接uva 10706 题目意思: 有一个数组 s[1] = 1 , s[2] = 1 2 , .......s[k] = 1....k,要求给定一个n表示数组的第几位,要求这个第几位是什么数。例如 n为1 时候是1 n为 2 时候是1 ,n 为3 时候为2 解题思路: 1:思路:预处理打表+查找 2:题目给的数据可以发现一些规律 ...

我是传奇 202

uva10706 Number Sequence

uva越来越不稳定了。。。连vj有种想换oj的冲动,

cgjiayou 525

uva 10706 Number Sequence(数学)

唉,被这道题虐惨了,从昨天晚上就开始做了,一直到现在才找到了一篇简短看得懂的题解,快把我的信心打掉完了,泪奔啊~~~~  我咋没有想出来这么好的方法呢,我竟然把int的范围给记错了,题上给的值就是int的最大范围,所以我们应该开long long int的 分析: 这道题求得是第n位上的数,昨天晚上我竟然敲的是第n个数,我没理解好,输出永远是一个一位的数字。。。看的题解是先求出所求位是在哪一个

勿忘初心 666

UVa 10706 / POJ 1019 Number Sequence (打表&O(1)算法)

10706 - Number Sequence Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1647 http://poj.org/problem?id=1019

AC,∑ndless 1509
上一篇: Uva 10341 Solve It
下一篇: 二分查找 UVa 10487 - Closest Sums,时间复杂度为O(2nlogn)
庞老板
博客等级 码龄15年 127粉丝 66原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

庞老板

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值