暑假集训 #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打一个表出来,直接看就 ...
随机推荐
- 【监控实践】【4.4】使用DMV和函数监控数据库状态和资源使用
1.查看当前实例运行进程 -- 核心DMV.函数.系统SP:/* 所有进程请求:sys.dm_exec_requests 所有进程与连接:sys.sysprocesses 系统函数,查看sql:sys ...
- postman测试webservice接口
- Spring(十二)--Spring AspectJ
Spring AspectJ AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法,所以它有一个专门的编译器用来生成遵守Java字节编码规范的Class文件. As ...
- .Net Core Grpc 实现通信
.Net Core 3.0已经把Grpc作为一个默认的模板引入,所以我认为每一个.Net程序员都有学习Grpc的必要,当然这不是必须的. 我在我的前一篇文章中介绍并创建了一个.Net Core 3.0 ...
- VMware Workstation改动存储位置之后,软件变成全英文,修改成中文的方法
今天想改动一下VMware Workstation的位置 改动之后打开软件,本来的中文改成了英文,整了很长时候,最后发现是因为改动一下位置之后,虽然zh_CN语言包还在,但是Vmware找不到本来的 ...
- 数据库or、in、<>、>=、<=、butween区别
操作前先关闭数据库缓存 #创建测试的test表 DROP TABLE IF EXISTS test; CREATE TABLE test( `id` ) NOT NULL, `name` ) DEFA ...
- Dango之视图函数
1.request对象 HTTPRequest对象就是咱们的视图函数的参数request def home(request): print(request) #<WSGIRequest: GET ...
- 从0开始入门ssm-crm系统实战
喜欢就点个赞呗! GitHub项目ssm-learn-crm show me the code and take to me,做的出来更要说的明白 1.1 克隆 git clone https://g ...
- ZeroMQ 三种模式python3实现
ZeroMQ是一个消息队列网络库,实现网络常用技术封装.在C/S中实现了三种模式,这段时间用python简单实现了一下,感觉python虽然灵活.但是数据处理不如C++自由灵活. Request-Re ...
- web攻击日志分析之新手指南
0x00 前言 现实中可能会经常出现web日志当中出现一些被攻击的迹象,比如针对你的一个站点的URL进行SQL注入测试等等,这时候需要你从日志当中分析到底是个什么情况,如果非常严重的话,可能需要调查取 ...