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. 思路: 我的想法是记录那些 ...
随机推荐
- 启动Tomcat服务时,出现org.apache.catalina.startup.VersionLoggerListener报错
启动Tomcat服务时,出现org.apache.catalina.startup.VersionLoggerListener报错解决办法:打开Tomcat安装后目录,进入conf文件夹,找到配置文件 ...
- read progress
<GNU+make中文手册-v3.80> 14 跟我一起写 Makefile 8 51单片机及c语言程序开发实例7/20/465
- 了解微信小程序
了解微信小程序 版权声明:未经博主授权,内容严禁转载分享! 微信小程序官方网址:https://mp.weixin.qq.com/cgi-bin/wx 某大神知乎专栏地址:七月在夏天 https:// ...
- Charles手机端抓包--证书
应用测试: Charles通过无线对手机进行抓包 测试系统: ubuntu 16.04 LTS 测试手机: IOS 10.3(14E277) Charles版本: Charles 4.1.4 手机证书 ...
- 20145317《网络对抗》shellcode注入&Return-to-libc攻击深入
20145317<网络对抗>shellcode注入&Return-to-libc攻击深入 学习任务 shellcode注入:shellcode实际是一段代码,但却作为数据发送给受攻 ...
- Java求两个数平均值
如何正确的求2个数的平均值.在练习算法二分查找的时候发现的,以前没有注意到的bug 备注:数据以int类型为例 一.以前的通用写法 /** * 求a+b平均值 * @param a * @param ...
- 第一个html文件
1.新建记事本文件,后缀改为.html 2.添加: <html> <head> <title>jude`s first web</title> & ...
- Linux内核分析--内核中的数据结构双向链表【转】
本文转自:http://blog.csdn.net/yusiguyuan/article/details/19840065 一.首先介绍内核中链表 内核中定义的链表是双向链表,在上篇文章--libev ...
- P2894 [USACO08FEB]酒店Hotel 线段树
题目大意 多次操作 查询并修改区间内长度==len的第一次出现位置 修改区间,变为空 思路 类似于求区间最大子段和(应该是这个吧,反正我没做过) 维护区间rt的 从l开始向右的最长长度 从r开始向左的 ...
- 网络量化——Quantized Convolutional Neural Networks for Mobile Devices
论文地址:https://arxiv.org/abs/1512.06473 源码地址:https://github.com/jiaxiang-wu/quantized-cnn 1. 主要思想 这篇文章 ...