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 数字找规律的更多相关文章

  1. HDU1005 Number Sequence(找规律,周期是变化的)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...

  2. 51nod 1770 数数字 找规律,注意进位,时间复杂度O(n)

    题目: 这题很简单,找规律即可. 考虑两次进位: 1.a*b时的进位. 2.aa*b时加法时进位. 代码: #include <bits\stdc++.h> using namespace ...

  3. shell习题第15题:看数字找规律

    [题目要求] 请仔细查看如下几个数字的规律,并使用shell脚本输出后面的十个数字 10 31 53 77 105 141... ... [核心要点] 计算两个数值之间的差值 [脚本] #!/bin/ ...

  4. HDU 2062 Subset sequence (找规律)

    题目链接 Problem Description Consider the aggregate An= { 1, 2, -, n }. For example, A1={1}, A3={1,2,3}. ...

  5. 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) ...

  6. 剑指 Offer 44. 数字序列中某一位的数字 + 找规律 + 数位

    剑指 Offer 44. 数字序列中某一位的数字 Offer_44 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author Wale ...

  7. [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+... ...

  8. HDU1005Number Sequence(找规律)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. 递推:Number Sequence(mod找规律)

    解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...

随机推荐

  1. Configure脚本支持说明

    在Linux上安装Nginx需要执行Configure脚本,该脚本需要做一些参数说明: 选项 说明 --prefix=<path> 指定Nginx软件的安装路径,若不指定默认安装在/usr ...

  2. Shell脚本编程(一)

    shell 脚本编程(一) 1 . shell 的作用 Shell的作用是解释执行用户的命令,用户输入一条命令,Shell就解释执行一条,这种方式称为交互式(Interactive),Shell还有一 ...

  3. Hive 教程(三)-DDL基础

    DDL,Hive Data Definition Language,数据定义语言: 通俗理解就是数据库与库表相关的操作,本文总结一下基本方法 hive 数据仓库配置 hive 数据仓库默认位置在 hd ...

  4. Radio stations CodeForces - 762E (cdq分治)

    大意: 给定$n$个三元组$(x,r,f)$, 求所有对$(i,j)$, 满足$i<j, |f_i-f_j|\le k, min(r_i,r_j)\ge |x_i-x_j|$ 按$r$降序排, ...

  5. ajax调用,action返回的中文为乱码的解决方案

    原文:ajax调用,action返回的中文为乱码的解决方案 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.c ...

  6. SQL学习(一)之简介

    什么是 SQL? SQL 指结构化查询语言(Structured Query Language) SQL 使我们有能力访问数据库 SQL 是一种 ANSI 的标准计算机语言 SQL 能做什么? SQL ...

  7. TensorFlow入门——MNIST初探

    import tensorflow.examples.tutorials.mnist.input_data as input_data import tensorflow as tf mnist = ...

  8. php 多肽实例

    多态定义:只关心一个接口或者基类,而不关心一个对象的具体类.(同一类型,不同结果) 这里两个例子: 第一个,我们发现,基类定义了标准,子类进行了自我规则的实现.这是多态的一个要求.同时,这是满足重写: ...

  9. 【异常】org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:

    1 Phoenix远程无法连接但是本地可以连接,详细异常 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found bindin ...

  10. linux下测试web访问及网络相关的命令

    curl命令 curl是linux系统命令行下用来简单测试web访问的工具. curl -xip:port www.baidu.com    -x可以指定ip和端口,省略写hosts,方便实用 -I  ...