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. C语言基础06

    函数: 一组特定功能的代码段,之所以使用函数,为了在文件多处需要同一段代码时可以多次重复利用,减少代码冗余. //函数的声明 返回值类型 函数名称 ( 数据类型 形参1,数据类型 ,形参2 ) ; / ...

  2. MYSQL 维护表的常用 5 方法

    方法 1. analyze table: 本语句用于分析和存储表的关键字分布.在分析期间,使用一个读取锁定对表进行锁定.这对于MyISAM, BDB和InnoDB表有作用. 方法 2. CHECK T ...

  3. 微软源代码管理工具TFS2013安装与使用图文教程

    微软源代码管理工具TFS2013安装与使用图文教程 这篇文章主要介绍了微软源代码管理工具TFS2013安装与使用图文教程,本文详细的给出了TFS2013的安装配置过程.使用教程,需要的朋友可以参考下 ...

  4. 何謂COB (Chip On Board) ?介紹COB的演進歷史

    COB (Chip On Board)在電子製造業已經是一項成熟的技術了,可是一般的組裝工廠對它的製程並不熟悉,也許是因為它使用到一些 wire bond 的積體電路(IC)封裝技術,所以很多的成品或 ...

  5. linux之SQL语句简明教程---ALTER TABLE

    在表格被建立在资料库中后,我们常常会发现,这个表格的结构需要有所改变.常见的改变如下: 加一个栏位 删去一个栏位 改变栏位名称 改变栏位的资料种类 以上列出的改变并不是所有可能的改变.ALTER TA ...

  6. WIN7 Wireshark: There are no interfaces on which a capture can be done

    有的时候我们在Windows7的环境下使用Wireshark的时候,比如点击[Interface List]的时候,出现错误. 错误内容如下: There are no interfaces on w ...

  7. Python-求助 SAE 如何使用第三方库? - 德问:编程社交问答

    Python-求助 SAE 如何使用第三方库? - 德问:编程社交问答 求助 SAE 如何使用第三方库?

  8. 浏览器桌面通知(notifications)

    近期在做公司后台管理系统,当有任务到来时,须要通知当事人,可是 当事人有可能在做别的,浏览器有可能会被最小化,这样就非常难看到通知了.经过查找发现有些浏览器能够使用noitfications.能够在桌 ...

  9. Oozie入门

    作者 Boris Lublinsky, Michael Segel ,译者 侯伯薇 发布于 2011年8月18日 |注意:QCon全球软件开发大会(北京)2016年4月21-23日,了解更多详情! 分 ...

  10. DevExpress GridControl一些属性使用方法总结

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...