Problem 1207 半数集问题 from http://acm.fzu.edu.cn/problem.php?pid=1207
2012-09-11 15:19
441 查看
![](http://acm.fzu.edu.cn/image/problem.gif)
Problem 1207 半数集问题
Accept: 1200 Submit: 3595
Time Limit: 1000 mSec Memory Limit : 32768 KB
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Problem Description
给定一个自然数n,由n开始可以依次产生半数集set(n)中的数如下。(1)n∈set(n); (2)在n的左边加上一个自然数,但该自然数不能超过最近添加的数的一半; (3)按此规则进行处理,直到不能再添加自然数为止。
例如,set(6)={6,16,26,126,36,136}。半数集set(6)中有6个元素。
注意半数集不是多重集。集合中已经有的元素不再添加到集合中。
编程任务
对于给定的自然数n,编程计算半数集set(n)中的元素个数。
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Input
本题有多组输入数据,你必须处理到EOF为止。每组数据只有1行,给出整数n。(0<n<201)
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Output
对于每组数据,输出只有1行,给出半数集set(n)中的元素个数。
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Input
6
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Output
6关键是处理重复元素,考虑新增的数小于等于100,100是不会有重复的。然后就是两位数有可能与一位数的产生重复。如48 100, 4 8 100。两位数产生的包含了一位数的,所以去掉的元素个数为halfSet(4).
#include<iostream> #include<cstdio> #include<cstdlib> #include<memory.h> using namespace std; int a[202] = {0}; int halfSet(int n){ if(a == 0){ int sum = 1; for(int i=1;i<=n/2;++i){ sum += halfSet(i); if(i>9 && ((i/10)<=(i%10/2))) sum -= halfSet(i/10); } a = sum; } return a ; } int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n; while(cin>>n){ cout<<halfSet(n)<<endl; } //fclose(stdin); //fclose(stdout); }
相关文章推荐
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- Problem 1202 信与信封问题 from http://acm.fzu.edu.cn/problem.php?pid=1202
- Problem 1057 ab from http://acm.fzu.edu.cn/problem.php?pid=1057
- Problem 1453 Bignum Arithmetic from http://acm.fzu.edu.cn/problem.php?pid=1453
- Problem 1410 变位词 from http://acm.fzu.edu.cn/problem.php?pid=1410
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- Problem 1046 Tempter of the Bone, from http://acm.fzu.edu.cn/problem.php?pid=1046
- Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607
- http://acm.fzu.edu.cn/problem.php?pid=1564 C(n,k)和素数P的问题
- http://acm.hdu.edu.cn/showproblem.php?pid=3790&&最短路径问题
- http://acm.hdu.edu.cn/showproblem.php?pid=2844&&背包问题
- 矩阵问题&&http://acm.hdu.edu.cn/showproblem.php?pid=1575
- 士兵队列训练问题http://acm.hdu.edu.cn/showproblem.php?pid=1276
- 最短路径问题 多加了一个费用 http://acm.hdu.edu.cn/showproblem.php?pid=3790
- http://acm.fzu.edu.cn/problem.php?pid=2113 数位DP
- http://acm.hdu.edu.cn/showproblem.php?pid=3591&&背包问题
- http://acm.hdu.edu.cn/showproblem.php?pid=1203(背包问题)
- http://acm.fzu.edu.cn/problem.php?pid=1698 最大乘积
- fzu 1402 中国剩余定理 http://acm.fzu.edu.cn/problem.php?pid=1402
- http://acm.hdu.edu.cn/showproblem.php?pid=1106&&排序