暑假集训 #3div2 C Sequence 数字找规律
C. Sequence (64 Mb, 1 sec / test)
Integer sequences are very interesting mathematical objects. Let us examine a sequence generated with the use of two operations: doubling and “digit sorting”. The latter operation consists in ascending-order sort of the individual digits in the decimal representation of the argument. For example, “digit sorting” of number 5726 gives 2567. The first member of the considered sequence is 1. To generate a member of the sequence from the previous member, double the previous one and apply “digit sorting” to the result. The first 15 members of the sequence are as follows: 1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156, … Write a program to determine the value of the n-th member of this sequence.
Limitations 1 ≤ n ≤ 2 147 483 647. Input The first line contains an integer n, the number of sequence member to be calculated. Output The output file should contain a single integer k, the value of the n-th member of the sequence. Example
Input.txt Output.txt 1 1
Input.txt Output.txt 6 23

题意:1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156.....这样的数字,每一个数字
是由前一个数字乘以2,然后将每位数字由小到大排序得到的,问第n个数字是多少,n<=1e9;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std; int a[500]={
0,1,2,4,8,16,23,46,29,58,116,223,446,289,578,1156,1223,2446,2489,
4789,5789,11578,12356,12247,24449,
48889,77789,155578,111356,122227,244445
};
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);//文件输入
int n;
while(~scanf("%d",&n))
{
if(n<=30) printf("%d\n",a[n]);
else {
n-=24;
if(n%6==0) printf("%d\n",a[30]);
else printf("%d\n",a[n%6+24]);
};
}
fclose(stdin);
fclose(stdout);
return 0;
}
分析:这题还是很好的,首先看到n<=1e9,这么大的算法,打表O(n)什么的是肯定不行了,那么考虑一下直接构造,会发现
比较复杂,而且还得借助前一个数字,复杂度又是O(n),那么考虑一下循环性质,找规律,多写出几个数字,就发现规律了
暑假集训 #3div2 C Sequence 数字找规律的更多相关文章
- HDU1005 Number Sequence(找规律,周期是变化的)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...
- 51nod 1770 数数字 找规律,注意进位,时间复杂度O(n)
题目: 这题很简单,找规律即可. 考虑两次进位: 1.a*b时的进位. 2.aa*b时加法时进位. 代码: #include <bits\stdc++.h> using namespace ...
- shell习题第15题:看数字找规律
[题目要求] 请仔细查看如下几个数字的规律,并使用shell脚本输出后面的十个数字 10 31 53 77 105 141... ... [核心要点] 计算两个数值之间的差值 [脚本] #!/bin/ ...
- HDU 2062 Subset sequence (找规律)
题目链接 Problem Description Consider the aggregate An= { 1, 2, -, n }. For example, A1={1}, A3={1,2,3}. ...
- HDU 1005 Number Sequence(找规律)
链接:传送门 题意:略 思路:f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7 -> f(n) = (A * f(n-1)%7 + B * f(n-1)%7) ...
- 剑指 Offer 44. 数字序列中某一位的数字 + 找规律 + 数位
剑指 Offer 44. 数字序列中某一位的数字 Offer_44 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author Wale ...
- [CSP-S模拟测试]:排列组合(数学 or 找规律)
题目描述 $T$组数据,每次给定$n$,请求出下式的值,对$10^9+7$取模: $$C_n^0\times C_n^0+C_n^1\times C_n^1+C_n^2\times C_n^2+... ...
- HDU1005Number Sequence(找规律)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 递推:Number Sequence(mod找规律)
解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...
随机推荐
- Logger Rate Limiter
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...
- [转帖]Oracle 数据库官方不支持VMWare
Oracle 数据库官方不支持VMWare [日期:2014-05-13] 来源:Linux社区 作者:myhuaer [字体:大 中 小] https://www.linuxidc.com/L ...
- Spread.NET 表格控件 V12.1 正式发布
Spread.NET 表格控件 V12.1 正式发布 加入动态数组,让公式运算更具效率 Spread.NET 是一个在功能和布局上与 Excel 高度类似的 .NET表格控件,目前已广泛应用于财务.预 ...
- C++笔记(3)——string.h相关的一些小知识
strlen() 用于得到字符数组中第一个\0前的字符的个数,格式如下: strlen(数组); 例子: #include <stdio.h> #include <string.h& ...
- redis 学习(8)-- redis 客户端 -- Jedis
redis 客户端 -- Jedis 1. Jedis 直连 本质是 TCP 连接. 执行流程 创建Jedis对象 通过Jedis执行命令 返回Jedis执行结果 关闭Jedis连接 demo 要使用 ...
- ftp服务器上传下载共享文件
1 windows下搭建ftp服务器 https://blog.csdn.net/qq_34610293/article/details/79210539 搭建好之后浏览器输入 ftp://ip就可以 ...
- 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本。
今天使用npm安装插件时出现了以下错误: 经查,原因:现用执行策略是 Restricted(默认设置) 解决办法: 1.win+X键,使用管理员身份运行power shell 2.输入命令:set-e ...
- arcgisJs之底图切换插件
arcgisJs之底图切换插件 底图切换插件在arcgis中有两种表现,如下: 1.两张底图切换 2.多张底图切换 一.两张地图切换 let basemapToggle = new BasemapTo ...
- java网络编程+通讯协议的理解
参考: http://blog.csdn.net/sunyc1990/article/details/50773014 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很 ...
- docker中centos7安装ssh服务
来源:https://blog.csdn.net/qq_32969313/article/details/64919735 docker安装好后,自己动手做个自己的docker镜像,首先需要从服务器p ...