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. Lowest Bit(hdoj1196)

    Lowest Bit Problem Description Given an positive integer A (1 <= A <= 100), output the lowest ...

  2. nginx请求体读取

    上节说到nginx核心本身不会主动读取请求体,这个工作是交给请求处理阶段的模块来做,但是nginx核心提供了ngx_http_read_client_request_body()接口来读取请求体,另外 ...

  3. Oracle EBS-SQL (MRP-3):检查例外信息查询_建议取消_采购订单.sql

    select msi.segment1                                    编码 ,msi.description                           ...

  4. delphi idhttp 实战用法(TIdhttpEx)

    以delphi XE8 自带indy(10.5.8.0)组件为例,分享实战中遇到的问题及解决方法. TIdHttpEx 用法实例01[多线程获取网页](包含完整源码) 实例02(如何Post参数,如何 ...

  5. QT GUI(主)线程与子线程之间的通信——使用跨线程的信号槽

    在主线程上,可以控制子线程启动,停止,清零 如果子线程启动的话,每一秒钟会向主线程发送一个数字,让主线程更新界面上的数字. 程序截图: 上代码: #include <QtGui> #inc ...

  6. c++11介绍

    C++11标准是 ISO/IEC 14882:2011 - Information technology -- Programming languages -- C++ 的简称[1]  . C++11 ...

  7. stl入门--reverse函数

    #include<iostream> #include<algorithm>          using namespace std; int main() {     ch ...

  8. 很好很实用的.net、网站系统后台模板

    本模板是程序园给大家提供的应用系统开发后台模板,主要使用div+css布局实现,菜单使用了ddaccordion.js菜单控件. 转载请标明:http://www.kwstu.com/ArticleV ...

  9. 热烈祝贺Polymer中文组织站点上线

    欢迎来到前端世界的明天 由于官网被墙, 所以 http://docs.polymerchina.org/ 其实是一件很有意义的事. 组件化和重用,一直是编程界几十年来前进的方向和目标,随着时间的推移和 ...

  10. 【MFC学习笔记-作业9-基于单击响应的计算平均成绩】【】

    要求..单击出现 一个输入成绩的框,点确定后,计算平均成绩 意义很大~ 完成对话框   再写个鼠标点击的响应部分 鼠标点击的响应部分为难点.... void CWj1401_0302140107_9V ...