ABC 336 C - Even Digits

这篇具有很好参考价值的文章主要介绍了ABC 336 C - Even Digits。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

先看一下ABC 336 C - Even Digits的题目(大致就是输入一个数n,输出第n个只由0,2,4,6,8组成的数)

题目

Time Limit: 2 sec / Memory Limit: 1024 MB

Score: 300 points

Problem Statement

A non-negative integer
n is called a good integer when it satisfies the following condition:

All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).
For example, 0, 68, and 2024 are good integers.
You are given an integer N. Find the N-th smallest good integer.

Constraints

  • 1≤N≤10^12
  • N is an integer.

Input

The input is given from Standard Input in the following format:
N

Output

Print the -th smallest good integer N

SAMPLES

Sample Input 1

8

Sample Output 1

24
The good integers in ascending order are .The eighth smallest is , which should be printed.0,2,4,6,8,20,22,24,26,28,…24

Sample Input 2

133

Sample Output 2

2024

Sample Input 3

31415926535

Sample Output 3

2006628868244228

解题过程

首先,数据范围已经到1e12,要开个long long以防爆int

其次,根据题目,0,2,4,6,8这五个数之间的组成,可以类比普通两位数的组成。对于普通的两位数,每位上由10个数字组成,取余是末位数,而整除10可以获得位数。对于这五个数组成的数的排序,整除5,即可获得这个数一共有几位数。

以上说的有点混乱,总的来说,就是利用递归来从后往前输出,递归结束标志就是到达第一位,将第一位输出出来。

代码段

#include<bits/stdc++.h>
using namespace std;
long long n;
int a[100];
void dg(long long n)
{
	if(!(n/5))
	{
		cout<<n*2;
		return ;
	}
	dg(n/5);
	cout<<n%5*2;
}
signed main()
{
	cin>>n;
	n--;
	dg(n);
}

总结

本题我主要用的递归方法,利用都是每位5个数和偶数的特点,通过取余乘2来实现结果的输出,注意一定不要忘了开long long!!!文章来源地址https://www.toymoban.com/news/detail-808097.html

到了这里,关于ABC 336 C - Even Digits的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Leetcode 357. Count Numbers with Unique Digits

    Given an integer n, return the count of all numbers with unique digits, x, where 0 = x 1 0 n 0 = x 10^n 0 = x 1 0 n . f(0) = 1 f(1) = 10 f(k) = 9 * 9 * 8 * … * (9 - k + 2)

    2024年02月19日
    浏览(33)
  • AtCoder Beginner Contest 336

    给定一个数 (n) ,将 long 中的 o 重复 (n) 次后输出。 模拟即可。 神奇的代码 给定一个数 (n) ,问 (n) 的二进制表示下的末尾零的数量。 即找到最小的 (i) 使得 (n (1 i)) 不为零的位置。枚举即可。 或者直接用内置函数 __builtin_ctz 。(count tail zero? 神奇的代码 定义一个数

    2024年01月20日
    浏览(31)
  • LeetCode //C - 328. Odd Even Linked List

    Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on. Note that the relative order inside both the even and odd groups should remain as it was in the input. You must solve the proble

    2024年01月25日
    浏览(30)
  • LeetCode每日一题——2520. Count the Digits That Divide a Number

    2520. Count the Digits That Divide a Number Given an integer num, return the number of digits in num that divide num. An integer val divides nums if nums % val == 0. Example 1: Input: num = 7 Output: 1 Explanation: 7 divides itself, hence the answer is 1. Example 2: Input: num = 121 Output: 2 Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twic

    2024年02月08日
    浏览(30)
  • STM32读取GPS数据-ATGM336H

    全球四大卫星定位系统     GPS 系统(美国)     BDS 系统(中国北斗)     GLONASS 系统(俄罗斯)     伽利略卫星导航系统(欧盟)     ATGM336H-5N 系列模块是 9.7X10.1 尺寸的高性能 BDS/GNSS 全星座定位导航模块系列的总称。该系列模块产品都是基于中科

    2024年01月25日
    浏览(33)
  • AtCoder Beginner Contest 336 A-E 题解

    比赛链接 :https://atcoder.jp/contests/abc336 比赛时间:2024 年 1 月 14 日 20:00-21:40 A题:Long Loong 标签 :模拟 题意 :给定一个 n n n ,输出 L L L 、 n n n 个 o o o 和 n g ng n g 。 题解 :按题意模拟即可。 代码 : B题:CTZ 标签 :模拟 题意 :给定一个十进制数 n n n ,求该数转换成 2 2

    2024年01月19日
    浏览(30)
  • 【STM32外设系列】GPS定位模块(ATGM336H)

    🎀 文章作者:二土电子 🌸 关注公众号获取更多资料! 🐸 期待大家一起学习交流!   我们在做一些项目时有时会需要进行GPS定位,获取自身的经纬度信息,这里使用的是中科微电子的GPS模块ATGM336H,带陶瓷天线。   该模块可以实现GPS定位,返回定位点的UTC时间和经纬

    2024年02月04日
    浏览(27)
  • 嵌入式外设集 -- GPS定位模块(ATGM336H)

    目录 一、模块介绍 关注微信公众号--星之援工作室 发送(GPS模块)  使用的注意事项  二、如何移植 usart2.c usart2.h 获取以及解析经纬度 显示经纬度 三、参考 ATGM336H是一种高性能的GPS模块,可以在较低功耗下提供高精度、高可靠性的位置信息服务。它采用了SiRFstarII

    2024年02月08日
    浏览(33)
  • The Node.js path can contain only letters,digits,periods (.),underscores...

    The Node.js path can contain only letters,digits,periods(.),underscores(_), hyphens (-), colon (:) and backslash(); 解决办法: DevEco Studio设置Nodejs提示路径只能包含英文、数字、下划线等-CSDN博客 补充: 文件路径:C:Users***AppDataRoamingHuaweiDevEcoStudio3.1optionsother.xml 也可以在DevEco Studio中,选择路径

    2024年02月04日
    浏览(36)
  • STM32——定位模块ATGM336H,数据解析,提取经纬度

    ATGM336H定位模块支持GPS系统,BDS(北斗)系统,GLONASS(俄罗斯)系统,伽利略卫星导航系统(欧盟)。这个模块要拿到室外才能接收到信号,且初次初始化或者隔太久时间没有启用会导致获取定位信息的时间很长。 可以使用中科微电子提供的集成软件设置模块,可以设置串口

    2023年04月11日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包