sgu 108 Self-numbers 2
题意:这样的数有几个?
模仿筛法就能解出,但是内存不够。这就需要重复利用数组,用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的更多相关文章
- 离线 + 位优化 - SGU 108 Self-numbers 2
SGU 108 Self-numbers 2 Problem's Link Mean: 略有这样一种数字:对于任意正整数n,定义d(n)为n加上n的各个位上的数字(d是数字的意思,Kaprekar发明 ...
- Self-numbers 2 - SGU 108
翻译:引自 http://www.cnblogs.com/yylogo/archive/2011/06/09/SGU-108.html 在1949年印度的数学假D.R. Kaprekar发现了一种叫做 ...
- sgu 108 Self-numbers II
这道题难在 hash 上, 求出答案很简单, 关键是我们如何标记, 由于 某个数变换后最多比原数多63 所以我们只需开一个63的bool数组就可以了! 同时注意一下, 可能会有相同的询问. 我为了防止 ...
- SGU 159.Self-Replicating Numbers
时间限制:0.5s 空间限制:6M 题意: 在b(2<b<36)进制中,找到所有长度为n(0<n<2000)的自守数k,满足k^2%b^n=k,字典序输出. ...
- 【CF edu 27 G. Shortest Path Problem?】
time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...
- 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 ...
- CodeForces845G-Shortest PathProblem?
You are given an undirected graph with weighted edges. The length of some path between two vertices ...
- SGU 169 numbers 数学
169.Numbers Let us call P(n) - the product of all digits of number n (in decimal notation). For exam ...
- SGU 258 Almost Lucky Numbers 接近幸运数(数位DP)
题意: 定义一个具有2n位的正整数,其前n位之和与后n位之和相等,则为lucky数.给定一个区间,问有多少个正数可以通过修改某一位数从而变成lucky数?注意不能含前导0. 思路: 我的想法是记录那些 ...
随机推荐
- 能让程序做的事情坚决不用人来做——批量修复markdownlint MD034警告
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- Centos7下PHP的卸载与安装nginx
Centos7下PHP的卸载与安装nginx CentOS上PHP完全卸载,想把PHP卸载干净,直接用yum的remove命令是不行的,需要查看有多少rpm包,然后按照依赖顺序逐一卸载. 1.首先查看 ...
- 怎样把QQ群降级(1000人降到200或500人,500人降到200)
怎样把QQ群降级(1000人降到200或500人,500人降到200)QQ群只有升级的选项,没有降级选项,一旦升级为1000人,就无法直接降级为200人或500人,建群时选择了500人也无法降到200 ...
- Fine报表权限流程分析记录
Fine报表权限流程分析记录 URL访问三种类型的报表:第一个:BI报表 例如: http://192.25.103.250:37799/WebReport/ReportServer?op=fr_bi ...
- wireshark捕获表达式之Berkeley Packet Filter (BPF) syntax
就网络抓包来说,绝大部分的情况下,我们都是对特定的ip/端口/协议进行捕获和分析,否则就会有大量的垃圾报文,使得分析和性能低下.大部分的抓包工具都采用BPF语法,具体可参考 http://biot.c ...
- 09: xmltodict 模块将xml格式转成json格式
1.1 : xmltodict 模块将xml格式转成json格式 <?xml version="1.0"?> <!--#版本号--> <data> ...
- Win32 实现 MFC CFileDialog 对话框
void CWriteWnd::OpenFileDialog() { OPENFILENAME ofn; TCHAR szFile[MAX_PATH] = _T(""); Zero ...
- JAVA I/O(五)多线程网络Socket和ServerSocket
上篇文章介绍了Socket和ServerSocket简单使用和源码,服务器端会对每个客户端请求创建一个线程,为使服务器端能同时处理多个客户端请求,可以采用多线程的方式.本文仅对实例进行简单记录,如下. ...
- Python3基础 函数 有参数有返回值 对传入的参数加1
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- JavaScript:值类型 引用类型
JavaScript类型 (1)值类型:数值.布尔值.null.undefined. (2)引用类型:对象.数组.函数. 1.string var str="hongda"; v ...