题意:这样的数有几个?

模仿筛法就能解出,但是内存不够。这就需要重复利用数组,用100大小的数组,所有的数对100取模。对于一个数,比如71,就在arr[78]=71记录下来。到78时,检查78-71<90。说明近期有数能产生78。而178对100取模也是78,如果后来(比178小90以内的数)没有数能产生78。那么178-arr[178]将>90就是符合条件的。而比178小90以内的数只能产生178,不可能产生78或者278。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF;
int apr[SZ];
int arr[SZ],sz;
map<int,int> mp; int dgt(int x)
{
int res=;
for(;x;res+=x%,x/=);
return res;
} void init(int x)
{
for(int i=;i<SZ;++i)apr[i]=-;
//cout<<"h"<<endl;
for(int i=;i<=x;++i)
{
apr[(i+dgt(i))%SZ]=i;
if(i-apr[i%SZ]>)
{
++sz;//cout<<sz<<" "<<i<<endl;
if(mp.find(sz)!=mp.end())mp[sz]=i;
}
}
} int main()
{
//cout<<ceil(-10.3)<<endl;
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int n,m;
cin>>n>>m;
vector<int> vct;
for(int i=;i<m;++i)
{
int tmp;
cin>>tmp;
mp[tmp]=;
vct.push_back(tmp);
}
init(n);
cout<<sz<<endl;
for(int i=;i<vct.size();++i)
{
if(i)cout<<" ";
cout<<mp[vct[i]];
}
cout<<endl;
return ;
}

sgu 108 Self-numbers 2的更多相关文章

  1. 离线 + 位优化 - SGU 108 Self-numbers 2

    SGU 108 Self-numbers 2 Problem's Link Mean: 略有这样一种数字:对于任意正整数n,定义d(n)为n加上n的各个位上的数字(d是数字的意思,Kaprekar发明 ...

  2. Self-numbers 2 - SGU 108

    翻译:引自 http://www.cnblogs.com/yylogo/archive/2011/06/09/SGU-108.html 在1949年印度的数学假D.R. Kaprekar发现了一种叫做 ...

  3. sgu 108 Self-numbers II

    这道题难在 hash 上, 求出答案很简单, 关键是我们如何标记, 由于 某个数变换后最多比原数多63 所以我们只需开一个63的bool数组就可以了! 同时注意一下, 可能会有相同的询问. 我为了防止 ...

  4. SGU 159.Self-Replicating Numbers

    时间限制:0.5s 空间限制:6M 题意:         在b(2<b<36)进制中,找到所有长度为n(0<n<2000)的自守数k,满足k^2%b^n=k,字典序输出.   ...

  5. 【CF edu 27 G. Shortest Path Problem?】

    time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...

  6. Codefroces Educational Round 27 845G Shortest Path Problem?

    Shortest Path Problem? You are given an undirected graph with weighted edges. The length of some pat ...

  7. CodeForces845G-Shortest PathProblem?

    You are given an undirected graph with weighted edges. The length of some path between two vertices ...

  8. SGU 169 numbers 数学

    169.Numbers Let us call P(n) - the product of all digits of number n (in decimal notation). For exam ...

  9. SGU 258 Almost Lucky Numbers 接近幸运数(数位DP)

    题意: 定义一个具有2n位的正整数,其前n位之和与后n位之和相等,则为lucky数.给定一个区间,问有多少个正数可以通过修改某一位数从而变成lucky数?注意不能含前导0. 思路: 我的想法是记录那些 ...

随机推荐

  1. SpringBoot之统一异常处理

    异常,不仅仅是程序运行状态的描述,还可以使得代码编写更加的规范   1.自定义异常:FieldValueInvalidException package com.geniuses.sewage_zer ...

  2. web前端----jQuery事件

    事件 常用事件 click(function(){...}) hover(function(){...}) blur(function(){...}) focus(function(){...}) c ...

  3. 从JavaWeb的角度认识Nginx

    作为一名JavaWeb方向程序员,更多的是写服务器后台代码,但是俗话说,不想当架构师的程序员不是好程序员,我们要对并发.负载等词汇进行深入探索. 一.重新认识Tomcat Tomcat属于轻量级的We ...

  4. 06: Django Admin

    目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...

  5. 20165211 获奖感想及java课程总结

    20165211 获奖感想及java课程总结 理论脱离实践是最大的不幸.--达芬奇 这句话,是我在学习Java之前,假期内写的20165211 学习基础和C语言调查里的所引用的一句话,是当时我对Jav ...

  6. UVa 10285 Longest Run on a Snowboard - 记忆化搜索

    记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...

  7. dp问题 -挑战例题 2017-7-24

    01 背包 题意: 在N件物品取出若干件放在容量为W的背包里,每件物品的体积为W1,W2……Wn(Wi为整数),与之相对应的价值为P1,P2……Pn(Pi为整数).求背包能够容纳的最大价值. f[i] ...

  8. 【深度学习】Pytorch 学习笔记

    目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...

  9. HDU 1083 Courses(二分图匹配模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...

  10. Perl 获得当前路径

      1.有两种方法:1. use Cwd;my $dir = getcwd;#$dir中即为当前目录的完整路径信息.2. my $dir = $ENV{'PWD'};#ENV是一个散列,用于存放环境变 ...