题意:这样的数有几个?

模仿筛法就能解出,但是内存不够。这就需要重复利用数组,用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. Hive 体系结构介绍

    下面是Hive的架构图. 图1.1 Hive体系结构 Hive的体系结构可以分为以下几部分: (1)用户接口主要有三个:CLI,Client 和 WUI.其中最常用的是CLI,Cli启动的时候,会同时 ...

  2. Hive 入门学习线路指导

    hive被大多数企业使用,学习它,利于自己掌握企业所使用的技术,这里从安装使用到概念.原理及如何使用遇到的问题,来讲解hive,希望对大家有所帮助. 此篇内容较多:看完之后需要达到的目标: 1.hiv ...

  3. 2018-2019-2 20165209 《网络对抗技术》Exp7: 网络欺诈防范

    2018-2019-2 20165209 <网络对抗技术>Exp7: 网络欺诈防范 1 基础问题回答和实验内容 1.1基础问题回答 (1)通常在什么场景下容易受到DNS spoof攻击. ...

  4. 我是怎么样和Linux结缘并通过红帽RHCE认证的

    我高考完当时就是选择的计算机科学与技术专业,上大学以后联想到的和计算机相关的就只有写代码,开发,网站,网页设计,就没有其他的了,当时学习写代码也都是在Windows上,什么C#.C++之类的?大约在大 ...

  5. P3366 【模板】最小生成树(堆优化prim)

    堆优化prim #include<cstdio> #include<cstring> #include<queue> using namespace std; st ...

  6. 20165211 2017-2018-2 《Java程序设计》第4周学习总结

    20165211 2017-2018-2 <Java程序设计>第4周学习总结 教材学习内容总结 本周,我学习了书本上第五.六两章的内容,以下是我整理的主要知识. 第五章 子类与继承 子类与 ...

  7. MFC制作OCX

    1.新建工程 注意选择显示时注册,免得后面又去手动注册 2.工程解释,一般ocx是看类视图而不是解决方案 ①.xxxApp:类似整个工程的入口,有xxxApp.h和xxxApp.cpp,工程的初始化, ...

  8. C语言结构体,点运算和箭头运算

    C语言有一种数据类型叫结构体,其定义格式为: struct 结构体名 { 结构体成员变量定义; }; 如: struct student { char name[20]; int age ; doub ...

  9. 又一个改写MBR的病毒(TDSS TDL4)

    此毒为TDSS TDL4 的又一个变种.RIS2011 目前尚未收录此毒.此毒的主要行为是改写MBR,并在硬盘尾部的190个扇区内写入病毒代码.病毒的上述动作可穿透还原类软件对系统的保护.我在Acro ...

  10. ZooKeeper 增加Observer部署模式提高性能

    Observer:在不伤害写性能的情况下扩展ZooKeeper. 虽然通过Client直接连接到ZooKeeper集群的性能已经很好了,可是这样的架构假设要承受超大规模的Client,就必须添加Zoo ...