Self Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20864   Accepted: 11709

Description

In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence

33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ...

The number n is called a generator of d(n). In the sequence above,
33 is a generator of 39, 39 is a generator of 51, 51 is a generator of
57, and so on. Some numbers have more than one generator: for example,
101 has two generators, 91 and 100. A number with no generators is a
self-number. There are thirteen self-numbers less than 100: 1, 3, 5, 7,
9, 20, 31, 42, 53, 64, 75, 86, and 97.

Input

No input for this problem.

Output

Write a program to output all positive self-numbers less than 10000 in increasing order, one per line.

Sample Input

Sample Output

1
3
5
7
9
20
31
42
53
64
|
| <-- a lot more numbers
|
9903
9914
9925
9927
9938
9949
9960
9971
9982
9993

Source

Mid-Central USA 1998
这题第一眼看上去就觉得应该要用什么特殊方法,要不然会超时,可是最后没想到根本不会超时,我在调试中提交了n次Runtime error,让我几乎快疯了,后来当我把定义的bool数组移到main函数外就ac了,这让我百思不得其解,难道main函数内部定义一个10000长度的bool数组会超过限制吗
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXn = ;
int numOf_Digit(int number)
{
int sum = number;
while(number>=)
{
sum += number%;
number /=;
}
sum+=number ;
return sum;
}
bool vis[MAXn];
int main()
{ memset(vis,true,sizeof(vis));
for(int i=;i<;i++)
{
int t =numOf_Digit(i);
vis[t] = false;
}
for(int i = ;i<;i++)
if(vis[i]==true)
printf("%d\n",i);
return ;
}

当然直接把#define 去掉,直接就是vis[10000],并且取消掉那个运算函数,用一句int t = i + i/1000+(i/100)%10+(i/10)%10+i%10; 就可以0MS了,但个人风格,喜欢把功能变成函数

poj1316的更多相关文章

  1. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

随机推荐

  1. Financial Management--hdu1064

    Financial Management Problem Description Larry graduated this year and finally has a job. He’s makin ...

  2. 经典面试题(二)附答案 算法+数据结构+代码 微软Microsoft、谷歌Google、百度、腾讯

    1.正整数序列Q中的每个元素都至少能被正整数a和b中的一个整除,现给定a和b,需要计算出Q中的前几项, 例如,当a=3,b=5,N=6时,序列为3,5,6,9,10,12 (1).设计一个函数void ...

  3. Web常用函数介绍(LoadRunner相关)

    介绍大纲:1. web_url2. web_image3. web_link4. web_submmit_form 详细介绍: 一. web_url web_url 语法: Int Web_url(c ...

  4. Ubuntu 12.04安装NFS server

    首先安装nfs-kernel-server apt-get install nfs-kernel-server 然后创建一个目录: mkdir -p /opt/share 并赋予权限777: chmo ...

  5. Baidu Sitemap Generator插件使用图解教程

    这两天因为百度对本博客文章收录更新很慢,一直在网络查找真正的原因和解决方法.最终发现了柳城开发的Baidu Sitemap Generator WordPress插件,最终效果如果还需要验证一段时间. ...

  6. linux之SQL语句简明教程

    本教程参考http://www.1keydata.com/cn/sql/ 目的是让初学者了解linux下Mysql的操作,但是我仍想侧重于SQL语句的讲解 sql语句的学习将按照下图的流程: 当然在这 ...

  7. 【HDU】4092 Nice boat(多校第四场1006) ——线段树 懒惰标记

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  8. leetcode 326. Power of Three(不用循环或递归)

    leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...

  9. RHEL5.8安装Oracle11g

    1.安装环境[root@rusky-oracle11g ~]# uname -r2.6.18-308.el5[root@rusky-oracle11g ~]# cat /etc/issueRed Ha ...

  10. C#运用实例.读取csv里面的词条,对每一个词条抓取百度百科相关资料,然后存取到数据库

    第一步:首先需要将csv先装换成datatable,这样我们就容易进行对datatable进行遍历: /// 将CSV文件的数据读取到DataTable中 /// CSV文件路径 /// 返回读取了C ...