POJ 1316 (筛选法模拟)
来源:互联网 发布:淘宝退货太多会怎么样 编辑:程序博客网 时间:2024/05/16 23:01
采用筛选法模拟,设筛为数组g[],其中g[y]=x 表明y是x递增序列的一个数。故y为非自数。
#include <stdio.h>const unsigned N = 10000;unsigned g[N];unsigned sum_digit (unsigned x){ //计算d(x);if (x < 10) return x;unsigned sum=0;while (x){sum += x % 10;x /= 10;}return sum;}void sequence (unsigned x){ //找出一以x开头的一个递增序列while (x < N){unsigned next = x + sum_digit (x);if (next > N || g[next]!=next)return;g[next] = x;x = next;}}int main (){for (unsigned i=1;i<=N;i++)g[i]=i; //初始所有数为自数。for (unsigned i=1;i<=N;i++)sequence (i);for (unsigned i=1;i<N;i++)if (g[i] == i)printf ("%u\n",i);return 0;}
0 0
- POJ 1316 (筛选法模拟)
- POJ 1316 Self Numbers 筛选模拟
- (简单模拟——筛选法模拟2.2.1)POJ 1316 Self Numbers(生成数、自数)
- POJ-1316(类素数筛选法)
- 1216Assistance Required(筛选法模拟题意)
- (poj1.2.1)1970(筛选法模拟)
- POJ 2638 筛选法的经典运用
- 【筛选法】 POJ 2689 Prime Distance
- Parencodings(poj模拟法)
- POJ 2739 素数筛选
- poj 4087: 数据筛选
- poj 1411 素数筛选
- POJ 4087:数据筛选
- poj-2689素数筛选
- js中模拟筛选过滤
- Js模拟正则筛选关键字
- POJ 3518 Prime Gap(筛选法生成素数表)
- poj -- 2689 Prime Distance(筛选法求素数)
- .bash_profile和.bashrc的区别(如何设置生效)
- 额外的类路径(Additional Class Paths)
- 运行python manage.py syncdb时出现“cannot connect to MySQL server on 'localhost'”的解决方法
- SharePoint Designer crash when opening site
- hibernate配置,开发过程
- POJ 1316 (筛选法模拟)
- C#发送邮件的方法及实例代码
- C# System.Console成员
- Linux终端用户的8个技巧
- 黑马程序员----学习经验
- 核心配置(Core Configuration)
- 如何将脚本放在页面里?(转载)
- 【中断异常】系统调用
- C#数组(小练习)