暑假集训 #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打一个表出来,直接看就 ...
随机推荐
- python打印带颜色的字体
在python开发的过程中,经常会遇到需要打印各种信息.海量的信息堆砌在控制台中,就会导致信息都混在一起,降低了重要信息的可读性.这时候,如果能给重要的信息加上字体颜色,那么就会更加方便用户阅读了. ...
- CSS3鼠标悬停翻转按钮
在线演示 本地下载
- 记Tomcat进程stop卡住问题定位处理
部分内容参考自CSDN 测试环境通过agent注入了部分代码,其中包括几个Timer. 在通过启动脚本重启tomcat时,会一直有一个stop进程卡住,导致tomcat无法正常重启,进程卡住不动. 通 ...
- 关于Android studio调用高德地图的简单流程和要点
一,账号与Key的申请 注册成为高德开发者需要分三步: 第一步,注册高德开发者:第二步,去控制台创建应用:第三步,获取Key. 前2步都比较简单,这里说下第三步. 获取Key 1.进入控制台,创建一个 ...
- es6编译器(babel搭建)
1.安装Node.js,初始化项目 npm init -y 2.安装babel-cli(兼容至ie7) npm i @babel/core @babel/cli @babel/preset-env - ...
- java实现生产者和消费者问题
Java实现生产者和消费者问题 欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti
- CentOS7部署kettle
去官网下载kettle, 或者百度网盘下载(nnnk),解压到目录/opt/service/, 解压后的目录是data-integration kettle需要java环境才能运行,因此要安装Java ...
- 富文本编辑器--使用textarea即时更新文本域同步编辑器内容
使用 textarea wangEditor 从v3版本开始不支持 textarea ,但是可以通过onchange来实现 textarea 中提交富文本内容. <div id="di ...
- OpenSSL(1)密钥和证书管理
OpenSSL是一个开源项目,包括密码库和SSL/TLS工具集. 从项目的官方站点可以看到: OpenSSL项目是安全套接字层( secure sockets layer, SSL)和传输层安全( t ...
- Logback日志输出到ELK
用docker-compose本机部署elk docker-compose.yml version: "3" services: es01: image: docker.elast ...