UVA - 10706 Number Sequence(贪心)

STM32新手必看:3分钟搞定ST官网资料下载(附F0系列手册+外设库下载技巧) 本文为STM32开发新手提供高效获取ST官网技术资料的完整指南,重点介绍如何快速下载STM32F0系列数据手册和外设库。通过系统性的资源分类解析和实用下载技巧,帮助开发者快速定位所需文档,建立本地知识库,提升开发效率。 阅读详情

Problem B
Number Sequence
Input:
 standard input
Output: standard output
Time Limit: 1 second

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 of a sequence of positive integer numbers ranging from 1 to k, written one after another. For example, the first 80 digits of the sequence are as follows:

11212312341234512345612345671234567812345678912345678910123456789101112345678910

Input

The first line of the input file contains a single integer t (1 <=t <=25), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 <=i <=2147483647)

 

Output

There should be one output line per test case containing the digit located in the position i.

 

Sample Input�������������������������� Output for Sample Input

2

8

3

2

2



题目大意:给你一个升序的序列,序列由如下序列组成
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
1234567891011
12345678910
现在给你一个数字n,代表在第几个位置,现在请你输出这个位置的数字。
(1 <=n <=2147483647)


解析:这题主要用到贪心的思想。

先打表,开一个数组digit保存每行的数字的个数,再开一个数组sum保存到当前行所有数字的个数,因为n的值可能很大,sum要开成long long。

现在遍历sum的数组,找到第一个sum[i] >= n,计算出sum[i-1] 到 n的距离dis,再用一个cnt来计算到sum[i-1]的距离,当cnt >= dis时,求出cnt - dis 的距离,这个距离就是当前该数字的第几位,输出该位数的值。


#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
const int N = 100000;
ll sum[N];
ll digit[N];
void init() {
	sum[0] = 0;
	digit[0] = 0;
	for(int i = 1; i < N; i++) {
		digit[i] = digit[i-1] + log10(i) + 1;
		sum[i] = sum[i-1] + digit[i];
	}
}
int solve(int n) {
	for(int i = 1; i < N; i++) {
		if(n <= sum[i]) {
			ll dis = n - sum[i-1];
			int ans,cnt = 0;
			int j;
			for(j = 1; j <= i; j++) {
				cnt += (log10(j) + 1);
				if(cnt >= dis) {
					break;
				}
			}
			if(cnt == dis) {
				ans = j % 10;
				return ans;
			}else if(cnt > dis) {
				ans = j / pow(10,(cnt-dis));
				ans %= 10;
				return ans;
			}
		}
	}
	return 0;
}
int main() {
	init();
	int t,n;
	scanf("%d",&t);
	while(t--) {
		scanf("%d",&n);
		int ans = solve(n);
		printf("%d\n",ans);
	}
	return 0;
}

华为OD机试真题 新系统【网络数据包收发处理】 华为OD机试 新系统真题【网络数据包收发处理】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【网络数据包收发处理】多语言题解。 阅读详情

相关推荐

基于STM32的家用新风系统智能控制器 | 保姆式教程 开源可复刻

本项目基于STM32F103C8T6核心控制器,完整实现了家用新风系统智能控制器的全功能开发,覆盖多传感器数据采集、双模式控制、PID调速、异常报警、掉电记忆等核心功能,全程采用保姆式无跳步教学,从硬件选型、接线、CubeMX配置、代码开发、调试排坑全流程拆解,跟着步骤一步步操作,就能顺利完成项目复刻

ZhongWeiXiang9的博客 466

poj1019——规律题

题目链接:http://poj.org/problem?id=1019 A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consist...

mumei的博客 1423

当我们谈论Unidbg时我们在谈什么

文章目录一、前言二、使用Unidbg的工作量是什么三、补环境补的是什么3.1 运行环境缺失3.2 上下文缺失四、Unidbg 不是所有情况下最优的解决方案五、Unidbg在大多数情况下是好的方案六、Unidbg和风控无关七、尾声 一、前言 这是一篇漫谈Unidbg的文章,我对Unidbg的使用和理解都还很浅,日后会更新或修改看法,欢迎大佬指点,也期待同侪讨论。 二、使用Unidbg的工作量是什么 我们常规使用Frida + IDA的动静态分析中,工作可能是这样的 找线索→Frida Hook验证→验证成功继

lilac的博客 5788

Number Sequence(思维题)

Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of p

青春无悔 1373

基于gm/id方法的折叠式共源共栅放大器设计实践

本文详细介绍了基于gm/id设计方法进行折叠式共源共栅放大器设计的完整流程。该方法通过确定晶体管的跨导效率(gm/id)作为核心设计参数,将复杂的放大器设计转化为有明确路径的优化问题。文章以设计一个增益80dB、带宽1GHz的两级放大器为例,逐步拆解了从指标分解、关键晶体管工作点选取、到实战仿真与微调的全过程,特别强调了第二级设计对稳定性的影响以及相位裕度的调试技巧。

w8x9y0z1的博客 415

利用Android系统漏洞实现后台弹窗(外弹)

关键:从 Android 8.0(API 26)开始,禁止使用 context.sendBroadcast() 发送隐式广播(即没有指定 setPackage() 或明确组件的广播)。demo核心代码展示利用Android显示系统和广播系统的漏洞实现在后台弹窗的功能,支持最新Android15,16版本。核心功能都是在so层去做,大量使用了jni反调, 如果要上架到应用市场,需要对代码做进一步混淆,加固以应对市场安全扫描。3,开启虚拟显示窗口,这是个透明像素窗口。5,可开启一个线程,调用这个外弹窗口。

2018,再出发~ 1316

信工初赛08

【问题描述】 A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after anoth

qq_52684161的博客 428

csp-j/s

CSP-J/S 是中国计算机学会(CCF)主办的 ‌‌(Certified Software Professional Junior/Senior),是信息学奥赛(NOI)体系的入门级选拔考试,也是国内最具权威性的青少年编程能力认证之一。

gxyxxrYYDS的博客 2029

poj 1019 数论

Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31517 Accepted: 8948 Description A single positive integer i is given. Write a program to find

风华绝代 799

手把手教你用SIMCOM A7670C_FASL模组实现双路MQTT连接阿里云(附完整源码)

本文详细介绍了如何使用SIMCOM A7670C_FASL 4G模组实现双路MQTT连接阿里云,包括硬件配置、开发环境搭建、双路MQTT架构设计及实现细节。通过完整的源码示例和实战指南,帮助开发者快速掌握物联网设备开发中的多路MQTT连接技术,提升工业级应用的开发效率。

weixin_33696822的博客 227

【数据集】中国陆地生态系统通量观测网 ChinaFLUX

【数据集】中国陆地生态系统通量观测网 ChinaFLUX

WW、forever的博客 191

杂题-Number Sequence

总时间限制:1000ms 内存限制:65536kB 描述 A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 ..

w112348的博客 652

基于AI大模型实现自然语言转SQL、SQL解释、SQL优化和SQL转换

随着大数据和人工智能技术的发展,数据分析和数据挖掘在各行各业中的应用越来越广泛。SQL(Structured Query Language)作为关系数据库的查询语言,是数据分析的重要工具。然而,SQL语言的复杂性和专业性使得许多非技术背景的用户难以直接使用,阻碍了数据的广泛利用。为了降低SQL的使用门槛,许多研究者和企业开始探索如何通过自然语言处理(NLP)技术,将自然语言转化为SQL查询语句,从而让用户可以通过自然语言与数据库进行交互。

AI天才研究院 2239

poj1019:Number Sequence

题目: Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24168 Accepted: 6466 Description A single positive integer i is given. Write a program to find the digit located in the...

维生素C吃多了会上火 349

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

C - Number Sequence POJ - 1019 (递归)

C - Number Sequence  POJ - 1019  A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists ...

东风clz 313

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Number Sequence

Number Sequence 描述 A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one

weixin_45637770的博客 485

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Number Sequence poj 1019

Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of pos

Believe in the Future的专栏 689

POJ 1019 数论基础题

Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37350   Accepted: 10780 Description A single positive integer i is given. Write a program to

Turne的博客 1006

Number Sequence (啥啥啥思维)

Number Sequence A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence

galesaur_wcy 872

ACM: poj 第50题 一题递推数论题  …

Number Sequence Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a se

smile_benson 414

POJ:1019 Number Sequence

Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk consists of a sequence of positive...

WeChat:A15047825994 315

Digit Problem

Digit Problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1

u012629369的专栏 2128

百练1019 Number Sequence

百练1019 Number Sequence题目出处:http://poj.grids.cn/practice/1019 题目描述: A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number group

软件与编程的零零碎碎 1311

POJ 1019 Number Sequence(数学技巧轻松解决)

Number Sequence A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one a

Defepe 780

POJ1019 ---简单的数学找规律题

Number Sequence Time Limit:1000MS Memory Limit:10000K Total Submissions:24387 Accepted:6534 Description A single positive integer i is given. Write a program to find ...

weixin_30474613的博客 286

POJ 1019:Number Sequence 二分查找

Number Sequence Time Limit:1000MS Memory Limit:10000K Total Submissions:36013 Accepted:10409 Description A single positive integer i is given. Write a p...

weixin_33898876的博客 310
上一篇: UVA - 10057 A mid-summer night's dream.
下一篇: UVA - 10487 Closest Sums(二分查找)
HelloWorld10086
博客等级 码龄12年 88粉丝 614原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值