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. 思路: 我的想法是记录那些 ...
随机推荐
- Python tricks(6) -- python代码执行的效率
python作为一个动态语言, 本身学习曲线比较平滑, 效率相比起来会比c++和java低一些. 脚本语言都是运行时编译的, 这个对于效率的影响是非常大的. 我借用参考1的代码, 加了点代码impor ...
- python实现常量const
新建const.py: #-*-coding:UTF-8-*- #Filename: const.py # 定义一个常量类实现常量的功能 # # 该类定义了一个方法__setattr()__,和一个异 ...
- LoadRunner 自动关联、手动关联的帖子
https://www.guru99.com/correlation-in-loadrunner-ultimate-guide.html 这个网页里介绍了关联的概念,自动关联和手动关联的知识...
- Linux基础命令---lsusb
lsusb 显示本机的usb设备列表,可以显示出usb的详细信息,包括设备的读取速度和描述符.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE ...
- git仓库按时间、成员等维度分析统计
git 按时间打印所有成员代码提交: git log --since ==2018-01-01 --until=2018-12-31 --format='%aN' | sort -u | while ...
- 分享三个USB抓包软件---Bus Hound,USBlyzer 和-USBTrace(转)
源:分享三个USB抓包软件---Bus Hound,USBlyzer 和-USBTrace Bus Hound官方下载地址:http://perisoft.net/bushound/Bus Hound ...
- Ubuntu下使用face_recognition进行人脸识别
Face Recognition是一个基于Python的人脸识别库,在github上地址如下:https://github.com/ageitgey/face_recognition. 看着挺好玩,本 ...
- 20145330 《网络攻防》 MSF基础应用
20145330 <网络攻防> MSF基础应用 1.实验后回答问题 (1)用自己的话解释什么是exploit,payload,encode. exploit:进行渗透攻击的模块合集 pay ...
- CRC32是什么?
CRC32:CRC本身是“冗余校验码”的意思,CRC32则表示会产生一个32bit(8位十六进制数)的校验值.由于CRC32产生校验值时源数据块的每一个bit(位)都参与了计算,所以数据块中即使只有一 ...
- Vue 父组件循环使用refs调用子组件方法出现undefined的问题
Vue 父组件循环使用refs调用子组件方法出现undefined的问题 1. 背景 最近前端项目遇到一个问题,我在父组件中使用了两个相同的子组件child,分别设置ref为add和update.其中 ...