UVA 10696 - f91
来源:互联网 发布:美元投资渠道知乎 编辑:程序博客网 时间:2024/06/11 23:33
Problem A - f91
Time Limit: 1 second
Background
McCarthy is a famous theorician of computer science. In his work, he defined a recursive function, called f91, that takes as input a positive integer N and returns a positive integer defined as follows:
- If N ≤ 100, then f91(N) = f91(f91(N+11));
- If N ≥ 101, then f91(N) = N-10.
The Problem
Write a program, that computes McCarthy's f91.
The Input
The input tests will consist of a series of positive integers, each integer is at most 1,000,000. There will be at most 250,000 test cases. Each number is on a line on its own. The end of the input is reached when the number 0 is met. The number 0 shall not be considered as part of the test set.
Output
The program shall output each result on a line by its own, following the format given in the sample output.
Sample input
500910
Sample output
f91(500) = 490f91(91) = 91
本来以为这题还得推一下递推关系式再打表呢,结果直接递归打表都不会T
不过用了0.8s,差点就T掉了。
#include<cstdio>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<algorithm>#include<cmath>#include <cstring>#include <queue>using namespace std;#define eps 1e-20#define MAXN 1000000 + 10#define outstars cout << "*********" << endl;int f[MAXN];int ff(int n){ if(n <= 100) { return ff(ff(n + 11)); } else return n - 10;}int main(){ int n; for(int i = 1 ; i <= 1000000 ; i++) { f[i] = ff(i); //cout << f[i] << endl; } while(cin >> n , n) { printf("f91(%d) = %d\n",n,f[n]); } return 0;}/**/
- UVA 10696 - f91
- UVa 10696 - f91
- UVa 10696 f91 (water ver.)
- f91
- f91
- [G联赛总决赛] Super vs F91 (5)
- [G联赛总决赛] Super vs F91 (4)
- [G联赛总决赛] Super vs F91 (3)
- [G联赛总决赛] Super vs F91 (2)
- [G联赛总决赛] Super vs F91 (1)
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- 两数组最短距离
- leetcode Two Sum
- A*算法实现寻找较优路径
- sencha architect 2 官方实例 第一个实例
- 360使用勋章墙引导用户安装360安全浏览器
- UVA 10696 - f91
- About Class
- Servlet方式文件上传
- POJ-1040-Transportation
- !!!Chapter 10 Algorithm Design Techniques
- ASSIC码对照表
- Sql2008不同用户指定访问数据库的权限设置!
- Javascript日期格式化
- 咕噜咕噜