11353: 【原1353】functionf
题目
题目描述
author: yuan 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1353
题目描述
最近(是很久很久以前的事情了)我一直在研究一个很简单的函数,(如果我的记忆没有出现偏差)函数是这样的
If x<=100, F[x]=F[F[x+11]]
If x>=101, F[x]=x-10
现在我需要知道一些值对应的函数值。
(如果一时没有什么思路,也不要发呆,可以打个表看一下)
输入说明
输入文件包括若干行(最多2500000行),每行一个正整数x(x<=1000000)。
最后一行以0结束.注意0不是要求的X,只是一个结束标记。
输出说明
对应每个要求的X值,每行输出一个对应的F[x]函数值。
Sample input
100
101
0
Sample output
91
91
数据范围
对于10%以内的数据,x<=10
对于30%以内的数据,x<=100
对于100%以内的数据,按题目描述
yyong119's solution
#include <cstdio>
#define MAX_N 1000010
using namespace std;
inline int read() {
char ch = getchar(); int flag = 1, res = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') flag = -1, ch = getchar();
while (ch >= '0' && ch <= '9') res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
// return res * flag;
return res;
}
inline int f(int x) {
if (x <= 100) return f(f(x + 11));
else return x - 10;
}
int main() {
// int n = 100;
// for (int i = 0; i <= 100; ++i)
// printf("%d: %d\n", i, f(i));
int tmp = read();
while (tmp) {
printf("%d\n", tmp > 100 ? tmp - 10 : 91);
tmp = read();
}
return 0;
}